Code

Opened 7 years ago

Closed 5 years ago

#6296 closed (fixed)

[patch]ifequal, filter and hardcoded-string doesn't work

Reported by: philipp@… Owned by: thejaswi_puthraya
Component: Template system Version: master
Severity: Keywords: ifequal filter hardcoded string tplrf-fixed
Cc: thejaswi.puthraya@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi, I just experienced the following problem:

Let:

>>> url = "/home/test/"
>>> urlparts = url.trim("/").split("/")

['home', 'test']

In the template I have:

{% ifequal urlparts|first "home" %}test1{% endifequal %}
{% ifequal urlparts|first home %}test2{% endifequal %}

Only the "test2" gets shown.

Attachments (1)

6296.diff (3.1 KB) - added by thejaswi_puthraya 7 years ago.
patch and tests

Download all attachments as: .zip

Change History (5)

comment:1 Changed 7 years ago by thejaswi_puthraya

  • Cc thejaswi.puthraya@… added
  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Owner changed from nobody to thejaswi_puthraya
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

The problem with ifequal is that it accepts only variables and doesn't allow any filters. So the urlparts|first variable is not resolved. In the second case (mentioned in the ticket) when home (or any values say abc) is given, this variable too gets resolved as None (because it is neither a Float, Integer or String) in the IfEqual Node and hence the equality case arises.

I have added patches by replacing the Variable with a FilterExpression. Even if a plain Variable is given it gets resolved without any problems. I shall add a couple of tests very soon.

Changed 7 years ago by thejaswi_puthraya

patch and tests

comment:2 Changed 7 years ago by thejaswi_puthraya

  • Needs tests unset
  • Summary changed from ifequal, filter and hardcoded-string doesn't work to [patch]ifequal, filter and hardcoded-string doesn't work

This ticket looks very similar to #5756. But that ticket includes nodes like Cycle Node and Ifchanged Node. Since making such a big change would require a design decision, I have patched only for the Ifequal node.

comment:3 Changed 6 years ago by emulbreh

  • Keywords tplrf-fixed added

This would be fixed by the refactoring proposed in #7806.

comment:4 Changed 5 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [10119]) Fixed #5756, #6296 -- Most template tags can now handle filters in arguments.

Most of the hard work for this was done by akaihola.

There are still possibly some problems with the i18n template tags,
since they are written quite differently and a few other bug fixes have
to made before they can be fixed.

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.