On Tue, 2009-04-21 at 11:51 -0700, adrian wrote: > > I want to have an inclusion tag that builds a menu system, which has a > default config. > > default_config = [list of dicts here] > > @register.inclusion_tag('_nav_leftmenu.html') > def nav_leftmenu(menu_config=default_config): > # build stuff here to display menu system > > return {'menu_html': menu_html} > > I use this tag in my base.html as follows: > > {% load nav_leftmenu %} > {% nav_leftmenu menu_config %} > > This works fine but only if menu_config is defined in the view and > passed in the context to base.html. If it is not defined, django > throws an error even though I have defined the menu_config argument as > optional. > > Is there a way to do this (other than context processor)? Thanks
You can write tags that take optional arguments. Django contains a number of them. However, the inclusion_tag() shortcut is not designed to handle that case. But that's fine. It's a shortcut for one particular common case. You aren't using that case, so it's the wrong tool for that job. Write a normal template tag and you can handle the argument processing however you like. That's documented in the template tags for Python programmers documentation. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---