|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
Render a string as talI would like to be able to render an arbitrary string as tal, having the
tal statements evaluated correctly. How would I go about doing this? -- Mark Gibson <mark@...> _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talOn Mon, Nov 14, 2005 at 01:19:18PM -0700, Mark Gibson wrote:
> I would like to be able to render an arbitrary string as tal, having the > tal statements evaluated correctly. > > How would I go about doing this? I assume you mean TALES expressions. See: http://zopelabs.com/cookbook/1037762730 -- Paul Winkler http://www.slinkp.com _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talPaul Winkler wrote:
> On Mon, Nov 14, 2005 at 01:19:18PM -0700, Mark Gibson wrote: > >>I would like to be able to render an arbitrary string as tal, having the >>tal statements evaluated correctly. >> >>How would I go about doing this? > > I assume you mean TALES expressions. > See: > http://zopelabs.com/cookbook/1037762730 He might mean a full blown page template of course ;-) ...in which case he probably wants to instantiate a ZPT and execute it, but that feels horribly expensive, unless it's persisted somewhere like the ZODB. Mark, what are you actually trying to do here? ;-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talMark Gibson wrote at 2005-11-14 13:19 -0700:
>I would like to be able to render an arbitrary string as tal, having the >tal statements evaluated correctly. > >How would I go about doing this? You create a "Products.PageTemplates.ZopePageTemplate.ZopePageTemplate" with the string as "text", put it into the acquisition context by a call to its "__of__(context)" method (this defines 'here', 'container', 'request', ...) and then call it. You can do this in trusted code only... -- Dieter _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talOn Mon, 2005-11-14 at 13:38, Paul Winkler wrote:
> On Mon, Nov 14, 2005 at 01:19:18PM -0700, Mark Gibson wrote: > > I would like to be able to render an arbitrary string as tal, having the > > tal statements evaluated correctly. > > > > How would I go about doing this? > > I assume you mean TALES expressions. > See: > http://zopelabs.com/cookbook/1037762730 Thanks for your suggestion. This has shed some light on the subject. However, what I'm looking for is being able to take a string such as '<div tal:content="here/absolute_url">The url</div>' and be able to evaluate the TALES expression in the string to produced something like: '<div>http://mydomain.com/theUrl</div>' Any chance there's a recipe for this? -- Mark Gibson <mark@...> _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talOn Tue, Nov 15, 2005 at 06:20:39PM -0700, Mark Gibson wrote:
> On Mon, 2005-11-14 at 13:38, Paul Winkler wrote: > > On Mon, Nov 14, 2005 at 01:19:18PM -0700, Mark Gibson wrote: > > > I would like to be able to render an arbitrary string as tal, having the > > > tal statements evaluated correctly. > > > > > > How would I go about doing this? > > > > I assume you mean TALES expressions. > > See: > > http://zopelabs.com/cookbook/1037762730 > > Thanks for your suggestion. This has shed some light on the subject. > > However, what I'm looking for is being able to take a string such as > '<div tal:content="here/absolute_url">The url</div>' > > and be able to evaluate the TALES expression in the string to produced > something like: '<div>http://mydomain.com/theUrl</div>' > > Any chance there's a recipe for this? Hmm. If you want TAL statements and all, I suspect you'll have to do as Chris suggested and instantiate a full-blown page template on the fly. I've never done that, if I were going to try I'd probably just start looking at the code in lib/python/Products/PageTemplates. You might be able to instantiate a PageTemplate rather than a ZopePageTemplate, which would be somewhat lighter as it leaves out a lot of stuff you surely don't care about (FTP support, ZMI management tabs, etc). -- Paul Winkler http://www.slinkp.com _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talMark Gibson wrote:
> However, what I'm looking for is being able to take a string such as > '<div tal:content="here/absolute_url">The url</div>' > > and be able to evaluate the TALES expression in the string to produced > something like: '<div>http://mydomain.com/theUrl</div>' > > Any chance there's a recipe for this? If you can explain to us why you think you want to do that, we can likely tell you what you really want to be doing ;-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talHi,
I'm not sure I entirely understand the goal here either, but you may want to look into the path method. Here's what I recently had to use it for. I'm building a little photo album application for my sister, it supports nested albums. I had a page template called view I was using as a method, but wanted to logically group the actions specific to a single image into a folder. So, I have a folder called view. When an image is viewed the URL looks like /some_album/some_pic.jpg/view/?display=large If I want to do operations or locate properties on some_pic.jpg I extract that part of the URL, and then pass it to the path function. The code looks like this: <span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]"> <span tal:define="global imgObj python:path('here/'+imgName)"></span> </span> HTH, Alan On 11/16/05, Chris Withers <chris@...> wrote: > Mark Gibson wrote: > > However, what I'm looking for is being able to take a string such as > > '<div tal:content="here/absolute_url">The url</div>' > > > > and be able to evaluate the TALES expression in the string to produced > > something like: '<div>http://mydomain.com/theUrl</div>' > > > > Any chance there's a recipe for this? > > If you can explain to us why you think you want to do that, we can > likely tell you what you really want to be doing ;-) > > Chris > > -- > Simplistix - Content Management, Zope & Python Consulting > - http://www.simplistix.co.uk > > _______________________________________________ > Zope maillist - Zope@... > http://mail.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope-dev ) > Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talAlan Warren wrote:
> single image into a folder. So, I have a folder called view. When an > image is viewed the URL looks like > /some_album/some_pic.jpg/view/?display=large > > The code looks like this: > <span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]"> > <span tal:define="global imgObj python:path('here/'+imgName)"></span> > </span> ouch. This is really contorted. Why do you use URL2 and URL3? Is imgObj not just 'here' anyway? What is the page template where this code comes from called? Why do you do a global define? Why two define statements instead of just one? Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talOn 11/18/05, Chris Withers <chris@...> wrote:
> Alan Warren wrote: > > single image into a folder. So, I have a folder called view. When an > > image is viewed the URL looks like > > /some_album/some_pic.jpg/view/?display=large > > > > The code looks like this: > > <span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]"> > > <span tal:define="global imgObj python:path('here/'+imgName)"></span> > > </span> > > ouch. Thanks. > > This is really contorted. Why do you use URL2 and URL3? To extract just the id of the image being viewed. The relative path from the template that presents the image to the image being presented will always match that pattern. > > Is imgObj not just 'here' anyway? Not in a manner I could easily work with, view is a folder containing index_html (the page template in question), and a handful of other page templates and scripts -- all of which are specific actions a user may wish to perform on a single image -- rather than on a whole album. Given the scenario I've outlined, do you have another suggestion? I agree this isn't aesthetically pleasing, but to me it was quite intuitive. > > What is the page template where this code comes from called? /view/index_html > > Why do you do a global define? Because I'm godless. > > Why two define statements instead of just one? So as to not post a massively long line of code to the list that would be even more spaghetti like. If it makes you feel any better the actual code is more in the form: <div tal:define="long_line here"> <!-- code that works on imgObj properties, --> </div> The question I was trying to answer wasn't about some coding style issue, but rather about how to convert a string path to an object at run-time. I included the URL manipulation as an illustration of when I had to use the path method. Cheers, Alan _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
|
|
Re: Render a string as talAlan Warren wrote:
> On 11/18/05, Chris Withers <chris@...> wrote: > >>Alan Warren wrote: >> >>>single image into a folder. So, I have a folder called view. When an >>>image is viewed the URL looks like >>>/some_album/some_pic.jpg/view/?display=large >>> >>>The code looks like this: >>><span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]"> >>> <span tal:define="global imgObj python:path('here/'+imgName)"></span> >>></span> >> >>ouch. > > > Thanks. > >>This is really contorted. Why do you use URL2 and URL3? > > To extract just the id of the image being viewed. The relative path > from the template that presents the image to the image being presented > will always match that pattern. *cries* >>Is imgObj not just 'here' anyway? > > Not in a manner I could easily work with, view is a folder containing > index_html (the page template in question), and a handful of other > page templates and scripts -- all of which are specific actions a user > may wish to perform on a single image -- rather than on a whole album. *sigh* I can see why you want this, but I'd loose the 'view' folder and just have the methods somewhere acquirable... in fact, I'd just rename your index_html to 'view'. Then you can just replace all instances of imgObj with 'context' >>Why do you do a global define? > > Because I'm godless. huh? > The question I was trying to answer wasn't about some coding style > issue, but rather about how to convert a string path to an object at > run-time. You should very rarely have to do this. If you end up doing this, big alarm belsl should start ringing ;-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk _______________________________________________ Zope maillist - Zope@... http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) |
| Free embeddable forum powered by Nabble | Forum Help |