[Solved] Use of integers in conditional template statements

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
cabot
Registered User
Posts: 689
Joined: Sat Jan 07, 2012 4:16 pm
Contact:

[Solved] Use of integers in conditional template statements

Post by cabot »

Hello,

I would like to know the best way to format numbers used as comparison values in conditional template statements.
With or without quotes?

Code: Select all

{% if FOO eq '0' %}
or
{% if FOO eq 0 %}
I would tend not to use quotes but I see both formats being used.
Last edited by Mick on Wed Mar 29, 2023 1:55 pm, edited 2 times in total.
Reason: Solved.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Use of integers in conditional template statements

Post by GanstaZ »

This should answer your question:

Code: Select all

{% set FOO = 0 %}

{% if FOO is same as('0') %}
    string
{% endif %}

{% if FOO is same as(0) %}
    Int
{% endif %}
twigfiddle
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
cabot
Registered User
Posts: 689
Joined: Sat Jan 07, 2012 4:16 pm
Contact:

Re: Use of integers in conditional template statements

Post by cabot »

So no quotes, thanks!
Post Reply

Return to “Extension Writers Discussion”