I’m making a custom template tag, and I want to be able to pass it in any sort of value. The use case is something like this:
{% include_with_args "path_to_template.html" simple_var an_object.foo.bar "A String" %}
When evaluating my custom template code, I want to evaluate simple_var, an_object.foo.bar, and "A String", the same way Django would normally. Currently I have
these_args = [context[arg_name] for arg_name in self.arg_names]
However, this only works for variable names (simple_var).
How do I get my template to evaluate these strings just like Django would? That is, if .foo is a function that returns a dict with a "bar" key it should evaluate it as expected: an_object.foo()["bar"].
In simple terms: I want to evaluate an expression to a value. How do I do that from a custom template?
It’s actually very simple. Instead of:
do:
Of course, now
arg_nameis a misnomer, so I changed that, but just wrote it this way to elucidate the differences.