Mailing List Archive

calling specific python code in jinja2 template
Hi all,

I'm currently migrating TracDownload plugin to jinja2. I am encountering
some problems to call trac Ressource from jinja2 template. I tried to add
the function in jinja2 environment before rendering it, but unfortunatly it
doesn't work. Does somebody have any idea on how to pass cutom python
funstion to jinja2 with trac?

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/959d41ec-d15b-4816-83a9-694fd923e462o%40googlegroups.com.
Re: calling specific python code in jinja2 template [ In reply to ]
On Mon, Jul 27, 2020 at 10:49 AM Cedric Lugnier <cedriclugnier@gmail.com>
wrote:

> Hi all,
>
> I'm currently migrating TracDownload plugin to jinja2. I am encountering
> some problems to call trac Ressource from jinja2 template. I tried to add
> the function in jinja2 environment before rendering it, but unfortunatly it
> doesn't work. Does somebody have any idea on how to pass cutom python
> funstion to jinja2 with trac?
>

I've seen some examples from older plugins where a python function is
defined in Genshi. In general, a better practice is to prepare the data
while processing the request and pass the data to a template. You can also
pass a function as a variable to the template. trac/web/chrome.py prepare
many functions that are available to the templates.
https://trac.edgewall.org/browser/tags/trac-1.4.2/trac/web/chrome.py#L633

- Ryan

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/CA%2BBGpn-hR1Nsr0z7Lz7VK0mHLhWfe3y_9n1V%3DL9g4XT2jhwVGQ%40mail.gmail.com.
Re: calling specific python code in jinja2 template [ In reply to ]
Hi,

Thank you.
I solved the problem by sending the results of the python code to the
template.
Cédric

On Monday, July 27, 2020 at 7:55:52 PM UTC+2 RjOllos wrote:

> On Mon, Jul 27, 2020 at 10:49 AM Cedric Lugnier <cedric...@gmail.com>
> wrote:
>
>> Hi all,
>>
>> I'm currently migrating TracDownload plugin to jinja2. I am encountering
>> some problems to call trac Ressource from jinja2 template. I tried to add
>> the function in jinja2 environment before rendering it, but unfortunatly it
>> doesn't work. Does somebody have any idea on how to pass cutom python
>> funstion to jinja2 with trac?
>>
>
> I've seen some examples from older plugins where a python function is
> defined in Genshi. In general, a better practice is to prepare the data
> while processing the request and pass the data to a template. You can also
> pass a function as a variable to the template. trac/web/chrome.py prepare
> many functions that are available to the templates.
> https://trac.edgewall.org/browser/tags/trac-1.4.2/trac/web/chrome.py#L633
>
> - Ryan
>

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/dd938c13-1b55-4060-80e8-8ae5f688b6b6n%40googlegroups.com.