> If interested, take the library from here:
> http://www.djangosnippets.org/snippets/363/

Interesting. I too was missing macro support, and implemented something
similar a couple weeks ago:

http://www.djangosnippets.org/snippets/343/

Michael

> -----Original Message-----
> From: django-users@googlegroups.com [mailto:[EMAIL PROTECTED]
> On Behalf Of Michal Ludvig
> Sent: Saturday, August 11, 2007 4:51 AM
> To: django-users@googlegroups.com
> Subject: Support for macros in templates
> 
> 
> Hi all,
> 
> This is a little announcement of a tag library for {% macro %} support
> in Django templates.
> 
> I have been using TAL template engine in my previous project and got
> used to the concept of "macros" as building blocks of the final HTML
> output. Now in Django I realised the missing support for "macros" is a
> serious limitation. I admit I may be too locked to a different mindset
> and perhaps the same things I need macros for could be achieved with
> pure Django templates. Maybe, maybe not. Anyway, I was missing macros so
> much that I decided to add them to Django.
> 
> If interested, take the library from here:
> http://www.djangosnippets.org/snippets/363/
> 
> Usage is like this:
> 
> 1) Load the macro library:
>         {% load macros %}
> 
> 2) Define a new macro called 'my_macro'
>    with parameter 'arg1':
>         {% macro my_macro arg1 %}
>         Parameter: {{ arg1 }} <br/>
>         {% endmacro %}
> 
> 3) Use the macro with a String parameter:
>         {% usemacro my_macro "String parameter" %}
> 
>    or with a variable parameter (provided the
>    Context defines 'somearg' variable, e.g. with
>    value "Variable parameter"):
>         {% usemacro my_macro somearg %}
> 
> The output of the above code would be:
>         Parameter: String parameter <br/>
>         Parameter: Variable parameter <br/>
> 
> It works pretty well and the only drawback is that the defined macros
> are local to each template file, i.e. are not inherited through
> {%extends ...%} and you can't have for instance some common macros
> defined in a separate file and include that file wherever needed. I'll
> try to solve that problem later. Perhaps through a new tag, for instance
> {%macrofile ...%} or something like that. Maybe someone will contribute
> a patch? ;-)
> 
> Enjoy and sorry for the spam
> 
> Michal
> --
> * http://www.logix.cz/michal
> 
> 
> 
> 
> 
> 
> 
> 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to