Opened 16 years ago

Closed 13 years ago

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

Download all attachments as: .zip

Change History (15)

by David Avsajanishvili, 16 years ago

Attachment: cat_filter.diff added

"cat" filter (concatenate argument with value)

by David Avsajanishvili, 16 years ago

Attachment: include_tag.diff added

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

by David Avsajanishvili, 16 years ago

Attachment: templates_doc.diff added

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

comment:1 by dc, 16 years ago

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

I think that's to many logic in template.

in reply to:  1 comment:2 by David Avsajanishvili, 16 years ago

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 by Johannes Dollinger, 16 years ago

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.

in reply to:  3 comment:4 by David Avsajanishvili, 16 years ago

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

milestone: post-1.0

comment:6 by Eric Holscher, 16 years ago

Triage Stage: UnreviewedDesign decision needed

comment:7 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:8 by dc, 15 years ago

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

comment:9 by Luke Plant, 13 years ago

Severity: Normal
Type: New feature

comment:10 by Jacob, 13 years ago

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 by anonymous, 13 years ago

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 by Julien Phalip, 13 years ago

That was me in the comment above.

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