How do I write an 'if' statement with PyroCMS Lex tags?

1.7k Views Asked by At

Here is my 'if' statement in a loop. Sometimes the description will exist and sometimes it will not. But all I am getting is the word LIKE and not ME when the description actually exists.

{{ description }}
{{ if description }}
    ME
{{ endif }}
LIKE
3

There are 3 best solutions below

0
On

If description can be evaluated to true, {{ if description }} may work.

But to test if a variable actually exists (~ is not null), you can use the keyword exists, like this: {{ if exists description }}.

If you are not sure that description always exists, you should also put it inside the 'if' scope, like that:

{{ if exists description }}
    {{ description }}
    ME
{{ endif }}
LIKE

Take a look at these links of documentation:

1
On

Try this:

{if ('{pyro:page:is_home}' == TRUE)}

ME
>
{else}

LIKE

{/if}
0
On

Need space between quote in condition "" to " ", And it's work.

{{ if description!=' ' }}
      True
{{ endif }}