You'll want to write your own Loader:

http://jinja.pocoo.org/docs/dev/api/#loaders

"Different loaders are available and you can also write your own if you
want to load templates from a database or other resources."

FunctionLoader might be an easy way to get started:

http://jinja.pocoo.org/docs/dev/api/#jinja2.FunctionLoader

Try wrapping a function which looks up templates in the database.

On Wed, Apr 13, 2016 at 11:22 PM, David Rueter <dbrue...@gmail.com> wrote:

> I am using the Jinja environment .from_string() method to create my
> templates from a strings stored in a database.
>
> This is working well, but I would like to be able to include
> templates--such as perhaps a common template for the header, a common
> template for the footer, etc.
>
> The Jinja Include extension seems only to support including templates from
> files--not templates that already exist in memory.
>
> I could accomplish what I am trying to do through string manipulation
> prior to instantiating the template .from_string() -- i.e. combine the
> various template strings into a complete template string, and only then
> instantiate a Jinja template object from that complete string--but I am
> wondering if there is a better way.
>
> I could probably accomplish this with a custom filter as well: pass in the
> ID for the template to include, instantiate that template from the string
> in the database, render that template, then have the filter return that
> output.  This however would add some overhead, and would require passing in
> a copy of the data variables to the other template render method.
>
> Does anyone have any suggestions as to how to include other templates when
> not using template files and instead creating templates from strings?
>
> --
> You received this message because you are subscribed to the Google Groups
> "pocoo-libs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pocoo-libs+unsubscr...@googlegroups.com.
> To post to this group, send email to pocoo-libs@googlegroups.com.
> Visit this group at https://groups.google.com/group/pocoo-libs.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pocoo-libs+unsubscr...@googlegroups.com.
To post to this group, send email to pocoo-libs@googlegroups.com.
Visit this group at https://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to