Code

#19059 closed Uncategorized (wontfix)

New {% decode %} tag

Reported by: mrechte Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

I would really appreciate a standard "decode" tag that would do a value decoding. Syntax would be:

{% decode var value1 newvalue1 [value2 newvalue2...] [default_value] %}

Examples:
{% decode weather_forecast 'with' 'selected' %}
If weather_forecast equals 'with' return 'selected' else returns

{% decode category '12' '1' '13' '1', '14' '2' '0' %}
If category equals '12', '13' returns '1'
If category equals '14' returns '2'
Any other value returns '0'

Thanks

Attachments (0)

Change History (2)

comment:1 follow-up: Changed 19 months ago by mrechte

  • Component changed from Uncategorized to Template system
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 in reply to: ↑ 1 Changed 19 months ago by ptone

  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for your submission

This kind of logic can be better handled by:

  • setting context in your view
  • the current if tag
  • a custom template tag

as your second example shows - the kwargs-as-a-list syntax gets very hard to follow

also, decode has several other meanings which would lead to ambiguity - but regardless of the name chosen - the functionality doesn't really warrant a new builtin tag.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.