[EMAIL PROTECTED] wrote:

>Say I want to have a reusable component, included via {% include %},
>which renders a product. So I only have to deal with layout,
>formatting, images, etc., once (I'm a big fan of re-use and DRY). The
>template fragment will have a lot of {{product.price}},
>{{product.picture}}, {{product.nunmInStock}}, etc.
>  
>
This is a work for a template tag and specifically for this case 
("include with paramteres") there is a helper inclusion_tag.

In a template tags library (file app_dir/templatetags/app_name.py):

    from django import template
    register=template.Library()
   
    @register.inclusion_tag('product.html')
    def product(arg):
      return {'product':arg}

Decorator @register.inclusion_tag takes template name for inclusion (it 
should be without ".html" if you don't use latest magic-removal). 
Function name will become a name of the tag. It accepts one argument and 
returns it in a context dictionary for the  included template.

You use it then like this:

    {% product bestOffer %}

... and bestOffer will be passed in product.html by the name 'product'.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to