Opened 8 years ago

Closed 5 years ago

Last modified 5 years ago

#8088 closed New feature (wontfix)

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

Reported by: David Avsajanishvili 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 David Avsajanishvili 8 years ago.
"cat" filter (concatenate argument with value)
include_tag.diff (1.8 KB) - added by David Avsajanishvili 8 years ago.
"include" tag modified so, it can process template filters
templates_doc.diff (1.8 KB) - added by David Avsajanishvili 8 years ago.
"cat" filter and "include" tag description update in documentation

Download all attachments as: .zip

Change History (15)

Changed 8 years ago by David Avsajanishvili

Attachment: cat_filter.diff added

"cat" filter (concatenate argument with value)

Changed 8 years ago by David Avsajanishvili

Attachment: include_tag.diff added

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

Changed 8 years ago by David Avsajanishvili

Attachment: templates_doc.diff added

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

comment:1 Changed 8 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 8 years ago by David Avsajanishvili

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 Changed 8 years ago by Johannes Dollinger

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 8 years ago by David Avsajanishvili

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 8 years ago by Jeff Anderson

milestone: post-1.0

comment:6 Changed 8 years ago by Eric Holscher

Triage Stage: UnreviewedDesign decision needed

comment:7 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:8 Changed 7 years ago by dc

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

comment:9 Changed 5 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:10 Changed 5 years ago by Jacob

Easy pickings: unset
Resolution: wontfix
Status: newclosed
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 5 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 5 years ago by Julien Phalip

That was me in the comment above.

Note: See TracTickets for help on using tickets.
Back to Top