librelist archives

« back to archive

Jinja Template Design and Variable Question

Jinja Template Design and Variable Question

From:
Carsten Brüggenolte
Date:
2013-03-12 @ 18:29
Hey guys, 

so I have this layout.html (main template). It includes a 'head.html' 
which uses a variable "posttitle". This variable is set in the "post.html"
which is used in the {% block content %} in the layout html.

But the head.html variable is empty and I can't figure it out how to pass 
it through layout to the head.html.

Thanks. 


-- Carsten

Re: [flask] Jinja Template Design and Variable Question

From:
Shawn Milochik
Date:
2013-03-12 @ 18:35
Are you extending or importing? Maybe you need to import with context:

http://jinja.pocoo.org/docs/templates/#import-visibility

Re: [flask] Jinja Template Design and Variable Question

From:
Carsten Brüggenolte
Date:
2013-03-12 @ 18:38
Hello Shawn  

These are my templates

layout.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/layout.html)


head.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/head.html)

and post.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/post.html)

Its probably not perfect, first time ninja user. I will read your link and
maybe its the thing I'm missing.

-- Carsten


Am Dienstag, 12. März 2013 um 19:35 schrieb Shawn Milochik:

> importing  

Re: [flask] Jinja Template Design and Variable Question

From:
Shawn Milochik
Date:
2013-03-12 @ 18:48
Try using your variable in post.html. If I understand your templates
and the docs correctly, it looks like you're doing it right, because
the context should be available to the included template.

So the next thing to check is that you're actually passing what you
think you're passing into the context. So, try putting the variable in
post.html, and if that doesn't work maybe post your view code. I
didn't see it in the git files you posted.

Shawn

Re: [flask] Jinja Template Design and Variable Question

From:
Carsten Brüggenolte
Date:
2013-03-12 @ 18:52
Hi Shawn,

the head.html had no access to the post variable thats why I had to set 
the variable outside the block content to use it.  



-- Carsten


Am Dienstag, 12. März 2013 um 19:38 schrieb Carsten Brüggenolte:

> Hello Shawn  
>  
> These are my templates
>  
> layout.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/layout.html)

>  
> head.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/head.html)
>  
> and post.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/post.html)
>  
> Its probably not perfect, first time ninja user. I will read your link 
and maybe its the thing I'm missing.
>  
> -- Carsten
>  
>  
> Am Dienstag, 12. März 2013 um 19:35 schrieb Shawn Milochik:
>  
> > importing  
>  
>  

Re: [flask] Jinja Template Design and Variable Question

From:
Carsten Brüggenolte
Date:
2013-03-12 @ 18:50
Strange  

I added the following lines to the 'layout.html' above the include statement.

{% set ptitle = ptitle %}
{% set pdescription = pdescription %}
{% set pkeywords = pkeywords %}


and all of a sudden it works.  


-- Carsten


Am Dienstag, 12. März 2013 um 19:38 schrieb Carsten Brüggenolte:

> Hello Shawn  
>  
> These are my templates
>  
> layout.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/layout.html)

>  
> head.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/head.html)
>  
> and post.html 
(https://github.com/cbrueggenolte/source_cbrueggenolte.de/blob/master/_templates/post.html)
>  
> Its probably not perfect, first time ninja user. I will read your link 
and maybe its the thing I'm missing.
>  
> -- Carsten
>  
>  
> Am Dienstag, 12. März 2013 um 19:35 schrieb Shawn Milochik:
>  
> > importing  
>  
>