librelist archives

« back to archive

Jinja2 template inheritance: extends templates outside app

Jinja2 template inheritance: extends templates outside app

From:
Sergey Kucheryavski
Date:
2012-07-18 @ 10:29
Hello all,

I am trying to make my first web site on Flask as a set of more or
less independent applications, e.g. "cms" for taking care of static
pages, "news" for news line, "library" for managing papers and books,
etc. My question is about Jinja2 template inheritance in such
structure. Let's say I have something like this:

/mysite
---/templates
   ---/admin
      ---layout.html
---/cms
   ---__init__.py
   ---/templates
      ---/admin
         ---layout.html
         ---cms.html

Where cms is an app. Here /templates/layout.html is a common layout
for all admin pages and /cms/templates/admin/layout.html is a layout
for cms admin pages which shall extend the /templates/layout.html. By
its turn the /cms/templates/admin/cms.html shall extend
/cms/templates/admin/layout.html. The question is how to make this
possible — to let an app template extends a template outside the app?
As far as I understood the template_folder parameter can have only one
value. Will be very grateful for any hints!

With best wishes,
Sergey

Re: [flask] Jinja2 template inheritance: extends templates outside app

From:
chrickso
Date:
2012-07-18 @ 11:09
Blueprints will let you set a different template folder for your cms routes:

http://flask.pocoo.org/docs/blueprints/#templates


On Wed, Jul 18, 2012 at 5:29 AM, Sergey Kucheryavski <
svkucheryavski@gmail.com> wrote:

> Hello all,
>
> I am trying to make my first web site on Flask as a set of more or
> less independent applications, e.g. "cms" for taking care of static
> pages, "news" for news line, "library" for managing papers and books,
> etc. My question is about Jinja2 template inheritance in such
> structure. Let's say I have something like this:
>
> /mysite
> ---/templates
>    ---/admin
>       ---layout.html
> ---/cms
>    ---__init__.py
>    ---/templates
>       ---/admin
>          ---layout.html
>          ---cms.html
>
> Where cms is an app. Here /templates/layout.html is a common layout
> for all admin pages and /cms/templates/admin/layout.html is a layout
> for cms admin pages which shall extend the /templates/layout.html. By
> its turn the /cms/templates/admin/cms.html shall extend
> /cms/templates/admin/layout.html. The question is how to make this
> possible — to let an app template extends a template outside the app?
> As far as I understood the template_folder parameter can have only one
> value. Will be very grateful for any hints!
>
> With best wishes,
> Sergey
>

Re: [flask] Jinja2 template inheritance: extends templates outside app

From:
Sergey Kucheryavski
Date:
2012-07-25 @ 13:56
Thanks a lot! I have read this before, but seems not careful enough.
Another issue, is it possible to extend a template in one blueprint from
another?

On Wed, Jul 18, 2012 at 1:09 PM, chrickso <chrickso@gmail.com> wrote:

> Blueprints will let you set a different template folder for your cms
> routes:
>
> http://flask.pocoo.org/docs/blueprints/#templates
>
>
> On Wed, Jul 18, 2012 at 5:29 AM, Sergey Kucheryavski <
> svkucheryavski@gmail.com> wrote:
>
>> Hello all,
>>
>> I am trying to make my first web site on Flask as a set of more or
>> less independent applications, e.g. "cms" for taking care of static
>> pages, "news" for news line, "library" for managing papers and books,
>> etc. My question is about Jinja2 template inheritance in such
>> structure. Let's say I have something like this:
>>
>> /mysite
>> ---/templates
>>    ---/admin
>>       ---layout.html
>> ---/cms
>>    ---__init__.py
>>    ---/templates
>>       ---/admin
>>          ---layout.html
>>          ---cms.html
>>
>> Where cms is an app. Here /templates/layout.html is a common layout
>> for all admin pages and /cms/templates/admin/layout.html is a layout
>> for cms admin pages which shall extend the /templates/layout.html. By
>> its turn the /cms/templates/admin/cms.html shall extend
>> /cms/templates/admin/layout.html. The question is how to make this
>> possible — to let an app template extends a template outside the app?
>> As far as I understood the template_folder parameter can have only one
>> value. Will be very grateful for any hints!
>>
>> With best wishes,
>> Sergey
>>
>
>