On Mar 20, 11:15 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Sunday, March 20, 2011 9:57:04 PM UTC, Turner wrote: > > > I'm working on a custom tag to which I would like to be able to pass > > template variables and filters. I found > > <code>Variable(value).resolve(context)</code> in the Django source. I > > have a couple of questions: > > > You don't need to look at the code, this is explicitly documented: > > http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/#pass...
Ah, I somehow missed that in my searching. > > > 1) Is it safe to use <code>Variable()</code>? That is, is it part of > > the public API? Not having visibility modifiers makes it a bit > > difficult to tell. > > Yes, since it is documented. > > > 2) Variable.resolve() works fine for, well, resolving a variable, but > > doesn't work with filters. That is, if I pass to my tag > > <code>some.context.variable|some_filter</code>, the tag will throw up > > on the last bit, saying that it can't find an attribute/key/method > > called "variable|some_filter". Is there an easy way I can have my tag > > apply any filters to the value passed in? > > AFAIK that should just work. The `with` tag, for example, works fine with > arguments that include filters. Here's the exception I get when I try a variable with filters: Caught VariableDoesNotExist while rendering: Failed lookup for key [path|split_path] It's raised on the following template call: {% my_tag list=form.instance.path|split_path %} (split_path is, obviously, a custom filter) In the code for my tag I have the following Variable(value).resolve(context) (where value is "form.instance.path|split_path") I'm using Django version 1.3 alpha 1, if that makes a difference. > -- > DR. -- 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.