Code

Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#8088 closed New feature (wontfix)

Template system improvement: "cat" filter, "include" tag with filters

Reported by: avsd Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords: cat concatenate include filter tag
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are two suggestions:

  1. Since we have add filter, that adds a value to integer variable, why not implement cat filter, which will concatenate strings? I think, it would be useful for many developers!
  1. include tag has two options: template name could be specified either as a quoted string, or as a variable. But for all that template filters cannot be used. It would be nice to allow developers to specify template name more flexibly, for example:
   {% include var_name|lower %}


or even like this (page5_ka.txt):

   {% include "page"|cat:pageid|cat:LANGUAGE_CODE|cat:"_.txt" %}

The diffs attached to the ticket do these things. At the same time, new revision of template system will be fully backwards-compatible with previous.
An only exception is - using quoted strings with quotes inside, like this:

    {% include "a"mysterious"template.txt" %}

Currently, template system accepts this string as a template name with doublequotes inside, while modified - won't. But, IMHO, nobody will name templates this case.

Attachments (3)

cat_filter.diff (717 bytes) - added by avsd 6 years ago.
"cat" filter (concatenate argument with value)
include_tag.diff (1.8 KB) - added by avsd 6 years ago.
"include" tag modified so, it can process template filters
templates_doc.diff (1.8 KB) - added by avsd 6 years ago.
"cat" filter and "include" tag description update in documentation

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by avsd

"cat" filter (concatenate argument with value)

Changed 6 years ago by avsd

"include" tag modified so, it can process template filters

Changed 6 years ago by avsd

"cat" filter and "include" tag description update in documentation

comment:1 follow-up: Changed 6 years ago by dc

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
{% include "page"|cat:pageid|cat:LANGUAGE_CODE|cat:"_.txt" %}

I think that's to many logic in template.

comment:2 in reply to: ↑ 1 Changed 6 years ago by avsd

I think that's to many logic in template.

Yes, but such usage is only an option available.
Although in some cases it might be useful.
See google-groups:
http://groups.google.com/group/django-developers/browse_thread/thread/21631ff4141a8db3

comment:3 follow-up: Changed 6 years ago by emulbreh

The {% include %} fix is a duplicate of #5862 and #5756, and would be fixed by #7806.

The cat filter is definitely useful, I call it concat and use it just like proposed here.

comment:4 in reply to: ↑ 3 Changed 6 years ago by avsd

Replying to emulbreh:

The {% include %} fix is a duplicate of #5862 and #5756, and would be fixed by #7806.

Good! Exactly that I have in mind!
Please, take into account this: http://code.djangoproject.com/attachment/ticket/5756/5756.3.patch

comment:5 Changed 6 years ago by programmerq

  • milestone set to post-1.0

comment:6 Changed 6 years ago by ericholscher

  • Triage Stage changed from Unreviewed to Design decision needed

comment:7 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:8 Changed 5 years ago by dc

See also #11687 which proposes to make 'add' filter more versatile.

comment:9 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:10 Changed 3 years ago by jacob

  • Easy pickings unset
  • Resolution set to wontfix
  • Status changed from new to closed
  • UI/UX unset

These are both useful features, but both can be implemented externally, and they don't cross the threshold of being widely useful. Thus, they're not a great match to include in Django's core.

Thanks!

comment:11 Changed 3 years ago by anonymous

It's hard to objectively assess what the threshold of being widely useful is. Speaking of the "concat" filter, I personally thought it actually crossed that threshold, based my own experience and that of several co-workers...

comment:12 Changed 3 years ago by julien

That was me in the comment above.

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.