On Thu, Jun 25, 2009 at 1:52 PM, Daniele Procida <dani...@apple-juice.co.uk>wrote:
> > I created a simple_tag: > > def news_for_this_page(page): > if page.entity_set.all(): # check page belongs to an entity first > e = page.entity_set.all()[0] # first entity will be only one > newslist = [] > for item in e.newsitem_set.all(): # get entity's news items > newslist.append(item.headline) # add them to the list > return newslist > else: > return "No news is good news" > > What this spits back into the page is: > > [u'Man bites dog', u'Dog bites man', u'Nixon resigns'] > > so obviously I need to process that list, making it a <ul> and putting > in the links before sending that to the template. > > To do this, I think I need my function to call another template to > render it appropriately - is that correct? > > Are there any shortcuts in this process? > > For example, to use my template tag I use {% news_for_this_page entity > %}. It would be neater to use something like {% news_for_this_page %}, > since entity will always be set. > Inclusion tags might help you out with the template idea, but generally for variables like this I like to put them in context like this: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#setting-a-variable-in-the-context Those docs should help you out a lot. Also the default tags are pretty good examples to look at: http://code.djangoproject.com/browser/django/trunk/django/template/defaulttags.py Hope that helps, Michael --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---