On Mar 3, 4:52 pm, alecs <alecs....@gmail.com> wrote:
> How can I send variable from my view function(which renders my
> template) to a template tag library(which is {% load blah %} in this
> template? I want to make my tag cloud independent from model:

Your template tag has access to any variable defined in the template
context (that is anything you pass from your view).

So, for example if you passed it from your view as "tag_model":

> register = Library()
>
> @register.inclusion_tag("tags/cloud.html", takes_context=True)
> def tag_cloud(context):
>     """Takes model and tag from context and returns cloud as a
> response."""
>     tag_list = Tag.objects.cloud_for_model(context['tag_model'], steps=9,
> distribution =
> tagging.utils.LOGARITHMIC,filters={'removed':False})
>     return {'tags' : tag_list}
(note that is completely untested).

Another way to do it would be to write your template tag to accept an
argument which is the model you are after (as a string), and use
"django.db.models.get_model" to get the model.

Peter

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

Reply via email to