Feature request for metal - default macros?
Heya, Quick question: Is there a good way to set a "default" macro? What I'm trying to do is setup a situation where we call: here/blah/skins/helpfile/macros/?language Where ?language resolves to the current language in use. What I want to do is say "if the language selected doesn't exist, use english" - or, from the macro side, "if the macro specified does not exist, use this macro instead". Is that doable easily? Is it something that could be included as a feature in metal? (I know there's probably other ways to do languages specifically, but I thought the feature itself may be useful generically. And we're doing languages this way because we're giving clients cvs access to the skins dir, and it's a nice easy way to say "if you want to change this block of text on this page, edit this file", without descending into ZMI stuff.) KevinL
http://www.zopelabs.com/cookbook/1014285275 On 10 Aug 2002, KevinL wrote:
Quick question: Is there a good way to set a "default" macro? What I'm trying to do is setup a situation where we call:
here/blah/skins/helpfile/macros/?language
Where ?language resolves to the current language in use. What I want to do is say "if the language selected doesn't exist, use english" - or, from the macro side, "if the macro specified does not exist, use this macro instead".
KevinL wrote:
Quick question: Is there a good way to set a "default" macro? What I'm trying to do is setup a situation where we call:
here/blah/skins/helpfile/macros/?language
Where ?language resolves to the current language in use. What I want to do is say "if the language selected doesn't exist, use english" - or, from the macro side, "if the macro specified does not exist, use this macro instead".
Is that doable easily?
make language a python script: language = "a string containing your language, got from wherever you get it from" if context.skins.helpfile.macros.has_key(language): return language else: reutnr 'english' cheers, Chris
On Sat, 2002-08-10 at 20:40, Chris Withers wrote:
make language a python script:
language = "a string containing your language, got from wherever you get it from" if context.skins.helpfile.macros.has_key(language): return language else: reutnr 'english'
Stefan Holek wrote:
(which lists a way to use pythonscripts to return the actual macro, rather than the word) I combined the two, with a method in my local python product, to give: def getHelptext(self): """ Returns the actual text for the help block on a page """ request = getattr(self,'REQUEST') baseUrl = self.baseUrl() ptl_name = request['URL0'].replace(baseUrl,'')[1:] language = self.getLanguage() skin = self.getSkin() subSkin = self.getSubSkin() ptl_page = self.restrictedTraverse('%s/skins/%s/%s/help/%s' % (self.realm(),skin,subSkin,ptl_name)) if ptl_page.macros.has_key(language): return ptl_page.macros[language] else: return ptl_page.macros['english'] (baseUrl, getLanguage, getSkin, etc are all my own methods) and the call in the page is <metal:block use-macro="here/getHelptext"></metal:block> Doesn't get much simpler. Thanks heaps for the quick responses from people - one of Zope's many assets :) KJL
participants (3)
-
Chris Withers -
KevinL -
Stefan H. Holek