#18651: Assignment tags should allow optional assignments ---------------------------------+-------------------------------------- Reporter: mitar | Owner: nobody Type: New feature | Status: reopened Component: Template system | Version: 1.4 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 1 | Needs documentation: 1 Needs tests: 1 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ---------------------------------+--------------------------------------
Comment (by tim_heap): After discussing with people in #django-dev, the following was proposed: * Merge these changes in to `simple_tag`. * Start `assignment_tag` on the deprecation path. For example: {{{ @register.simple_tag() def plain_output(): """ Use as `{% plain_output %}`. Prints 'bar' """ return 'bar' @register.simple_tag(assignable=True) def optional_assignment(): """ Use as either: * `{% optional_assignment %}` - prints 'bar' * `{% optional_assignment as foo %}` - assigns 'bar' to 'foo' """ return 'bar' @register.simple_tag(assignable=True, default_name='foo') def default_assignment(): """ Use as either: * `{% default_assignment %}` - assigns 'bar' to 'foo' * `{% default_assignment as foo %}` - assigns 'bar' to 'foo' """ return 'bar' }}} This has the down side of being unable to force assignment, as you currently can with `assignment_tag`. I do not see this being a problem though, as I can not think of a reasonable example where outputting a variable is so harmful that the possibility of it happening should be guarded against explicitly in the tag. If you really need this case, write a completely custom tag. -- Ticket URL: <https://code.djangoproject.com/ticket/18651#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.