Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja2: saying 'Render this macro inside another macro or template'

I have a number of macros I'd like to render within a common container macro or template. With pseudo-code:

Macro1

Macro2

Macro3

Container

In a template:

"render macro1 inside of Container" e.g. {{ macro1 with Container }}

I don't want to go through rendering Container and then the macro inside it everytime, I just need to specify, when this macro, enclose with this other macro

I think 'call' (http://jinja.pocoo.org/docs/templates/#macros) is what I'm looking for but I don't quite understand it right now. Any input, and how I can clarify this if it is not clear appreciated.

like image 464
blueblank Avatar asked Apr 03 '13 20:04

blueblank


1 Answers

This works for me:

{% macro _enclosure() %}
    <div id="topenclosure">hello I'm on top</div>
        {{ caller() }}
    <div id="bottomenclosure">hello I'm on the bottom</div>
{% endmacro %}

{% macro account_user_profile_macro(i) %}
    {% call _enclosure() %}
        {{i.__dict__}}
    {% endcall %} 
{% endmacro %}
like image 159
blueblank Avatar answered Sep 28 '22 14:09

blueblank