render/parse function ? (using <dtml-var x> in a property sheet ?) sheet ?)
Sorry to bother you all again, but solving this problem would save a lot of jumping through hoops and I was surprised that nobody else has encountered it. Consider : - we have a ZClass string property called 'myproperty'. - we set the value of 'myproperty' to "Hello <dtml-var FirstName>" where FirstName is a variable whose value is set to 'Fred' - we now try to render the value of 'myproperty' inside a DTML method using the DTML : <dtml-var myproperty> - as would be expected, the following is displayed - "Hello <dtml-var FirstName>" since it is just a string. But really we wanted it to display "Hello Fred" ie. to evaluate the DTML tags. Is there any method that can be called to parse the value of a property and evaluate the DTML ? Thank you very much, chas ps. To circumvent the above, I could create a DTML method called 'myproperty'. However, with 30 such properties it would be far nicer and faster to edit them in ZClass property sheets. I guess it would be nice if there were some ZClass property of type 'renderThis' where the contents will be rendered by Zope just as a DTML method's contents are. In lieu of this, any hacks would be appreciated :)
chas wrote:
Sorry to bother you all again, but solving this problem would save a lot of jumping through hoops and I was surprised that nobody else has encountered it.
Consider : - we have a ZClass string property called 'myproperty'. - we set the value of 'myproperty' to "Hello <dtml-var FirstName>"
How is this different than just creating a string property called 'FirstName' and: Hello <dtml-var FirstName> instead of <dtml-var myproperty>?
where FirstName is a variable whose value is set to 'Fred' - we now try to render the value of 'myproperty' inside a DTML method using the DTML : <dtml-var myproperty> - as would be expected, the following is displayed - "Hello <dtml-var FirstName>" since it is just a string. But really we wanted it to display "Hello Fred" ie. to evaluate the DTML tags.
Is there any method that can be called to parse the value of a property and evaluate the DTML ?
I see what you want to do here, coincidentally someone else asked something similar today. I'm not sure how useful it would be though. Perhaps you could think up some more interesting use cases than what you have here and put them on the InterfaceWishList: http://www.zope.org/Members/michel/Projects/Interfaces/ -Michel
At 04:07 PM 04/08/2000 -0700, you wrote:
chas wrote:
Sorry to bother you all again, but solving this problem would save a lot of jumping through hoops and I was surprised that nobody else has encountered it.
Consider : - we have a ZClass string property called 'myproperty'. - we set the value of 'myproperty' to "Hello <dtml-var FirstName>"
How is this different than just creating a string property called 'FirstName' and:
Hello <dtml-var FirstName>
instead of <dtml-var myproperty>?
Just a quick explanation of why this is desired :these properties are being used to hold the text for multiple languages. Word order is not the same in each case. eg. Consider displaying an error message that is language-dependent : "Sorry, the username Fred Flintstone is not available" "Desolee, le nom 'Fred Flintstone' n'est pas disponible" (Sorry, my French is poor. I'm actually doing this in 3 different Chinese character sets, Korean and Japanese as well as English but figured I'd spare you the double-byte charsets. The word order is totally different in Asian languages too.) So, I want to return one of several messages, depending on language : <dtml-var ErrorMsg_en> <dtml-var ErrorMsg_jp> <dtml-var ErrorMsg_cn> But each error message in itself consists of a constant string (eg. "I'm sorry, the username _____ is not available") and the variable(s) (eg. <dtml-var Username>) It looks like I'm going to have to use DTML methods but that really is going to be ugly to maintain and not very user-friendly. I had also thought of manually parsing the string too but figured this would slow things down even more.
where FirstName is a variable whose value is set to 'Fred' - we now try to render the value of 'myproperty' inside a DTML method using the DTML : <dtml-var myproperty> - as would be expected, the following is displayed - "Hello <dtml-var FirstName>" since it is just a string. But really we wanted it to display "Hello Fred" ie. to evaluate the DTML tags.
Is there any method that can be called to parse the value of a property and evaluate the DTML ?
I see what you want to do here, coincidentally someone else asked something similar today.
Ah, I assume to mean Graham Chiu's earlier message, to which you replied : [snip] Uhm... I don't know. What you want to turn your string into is an object that can evaluate DTML code, then you can call it from another tag such as var or call or in. This cannot be done from DTML, you need to drop to python to do this. Just instanciate a 'temporary' DTML object (proabably a method), feed it your string, and then call it. This could probably be done easily from an external method: <dtml-var "anExternalMethod("<dtml-var blah>")"> [/snip] OK. Thanks also to John Earl also for pointing me in the right direction on this one. The following sort of works: An external method 'externalRenderer' contains the following : from OFS.DTMLMethod import DTMLMethod def renderstring(str, REQUEST): m = DTMLMethod(str, REQUEST) return m() This works if the variable exists in the REQUEST object : eg. <dtml-call "REQUEST.set('x', 'Silly')"> <dtml-var "externalRenderer('Hello <dtml-var x> World', REQUEST)"> will display 'Hello Silly World' BUT if you have an image object called 'myimg' that is normally accessible with <dtml-var myimg>, you have to first force it into the REQUEST method : eg. <dtml-call "REQUEST.set('myimg', myimg)"> <dtml-var "renderme('Hello <dtml-var myimg> World', REQUEST)"> Which sort of defeats the purpose.
I'm not sure how useful it would be though.
To be honest, I've wanted this on many many occasions in the past and I know alot of other people I've worked with have wanted it too. Here's a classic example : You have a ZClass that is being used to store Articles (like Kevin's KMNews product). The ZClass contains a text property (amongst many other properties) called "main_story" where your content author writes his 300-word story. S/he uploads several images using the Zope image object but also wishes to control the positioning of the images. S/he wishes to write <dtml-var image1> in that text property 'main_story'. No can do. So, instead we've either had to fix a rigid template for where images are rendered (not good since image dimensions change and it's simply not aesthetic in many cases). Or usually make the content author create a DTML method called 'main_story'. Not as nice as a proper ZClass.
Perhaps you could think up some more interesting use cases than what you have here and put them on the InterfaceWishList:
Took a look - seems to go in circles... keep the UI guy away from LSD. chas
chas wrote:
How is this different than just creating a string property called 'FirstName' and:
Hello <dtml-var FirstName>
instead of <dtml-var myproperty>?
<snip translation requriments> This might be a bit too complex for DTML, you might want to try it all as a Python product, some kind of object that translates for you...
Ah, I assume to mean Graham Chiu's earlier message, to which you replied :
[snip]
Uhm... I don't know. What you want to turn your string into is an object that can evaluate DTML code, then you can call it from another tag such as var or call or in. This cannot be done from DTML, you need to drop to python to do this. Just instanciate a 'temporary' DTML object (proabably a method), feed it your string, and then call it. This could probably be done easily from an external method:
<dtml-var "anExternalMethod("<dtml-var blah>")">
[/snip]
OK. Thanks also to John Earl also for pointing me in the right direction on this one. The following sort of works:
An external method 'externalRenderer' contains the following :
from OFS.DTMLMethod import DTMLMethod def renderstring(str, REQUEST): m = DTMLMethod(str, REQUEST) return m()
This works if the variable exists in the REQUEST object :
eg. <dtml-call "REQUEST.set('x', 'Silly')"> <dtml-var "externalRenderer('Hello <dtml-var x> World', REQUEST)"> will display 'Hello Silly World'
BUT if you have an image object called 'myimg' that is normally accessible with <dtml-var myimg>, you have to first force it into the REQUEST method :
eg. <dtml-call "REQUEST.set('myimg', myimg)"> <dtml-var "renderme('Hello <dtml-var myimg> World', REQUEST)">
Which sort of defeats the purpose.
The reason this does not work is that the current Acquisition namespace is not available to 'm'. Neither is the DTML namespace. The only namespace you've provided for it is REQUEST. You'll need to make two changes, first, pass the current container (self) in as the client object, and pass the DTML namespace into the exernal method seperatly, like this: from OFS.DTMLMethod import DTMLMethod def renderstring(self, str, ns={}, REQUEST=None): m = DTMLMethod(str, REQUEST) return m(self, ns) Note how self is passed in, this is the current _Acquisition wrapped_ container that this method was called from. Notice also the new argument ns that defaults to an empty dictionary. I've defaulted REQUEST to None because it's a good habit. When m is called, a 'client' is passed, self, and a namespace. So now acquisition works with no changes, and if you want to pass in the DTML namespace use '_' Just Acquisition <dtml-var "externalRenderer('Hello <dtml-var myimg> World')"> Acquisition and DTML <dtml-var "externalRenderer('Hello <dtml-var myimg> World', _)"> I don't think you need to pass REQUEST in, it should be passed for you because it's in the external method signature. Untested.
Perhaps you could think up some more interesting use cases than what you have here and put them on the InterfaceWishList:
Took a look - seems to go in circles... keep the UI guy away from LSD.
It'll become second nature to you. After a while, you'll wonder how you lived without Wiki. -Michel
participants (2)
-
chas -
Michel Pelletier