This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Install & configuration » If statements in templates
expandshrink

If statements in templates

If statements in templates

Friday 17 January 2003 1:51:47 am - 9 replies

Is there some way to use an if-else type statement in the template files?

For example to only show a Heading if there is actually content under the heading. I've tried setting:

{let list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))}

Then wrapping the conditional text in a {section} block with the following types of {section} code, but I really don't know what they mean or even if I'm on the right track.
{section show=$list_count}
{section show=eq($list_count)}
{section show=and($list_count)}

Also wanted to know if there is a way to set and display a count variable within a loop.

like this:

{let count=0}
{section loop code here}
$count
{let count=$count+1}
{/section}

Thanks,

Mike

Friday 17 January 2003 1:05:32 pm

> Is there some way to use an if-else type statement in the
> template files?
>
> For example to only show a Heading if there is actually
> content under the heading. I've tried setting:
>
> {let
> list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))}
>
> Then wrapping the conditional text in a {section} block with
> the following types of {section} code, but I really don't
> know what they mean or even if I'm on the right track.
> {section show=$list_count}
> {section show=eq($list_count)}
> {section show=and($list_count)}
>

You are right, you may this syntax:

{section show=gt($list_count,0)}
...if ther is some content ...
{section-else}
...if there is no content...
{/section}

obviously, operators and, not, or, gt, eq are normal logical operators, just taking operands inside brackets.

In case you doubt in what meaning your variable takes print debug information for yourself, just to know to what value to compare:

{$list_count} will print its value on output HTML page.

> Also wanted to know if there is a way to set and display a
> count variable within a loop.
>
> like this:
>
> {let count=0}
> {section loop code here}
> $count
> {let count=$count+1}
> {/section}
>

There is some limit statement in loop, maybe it can help you; also loop can work on arrays (look for exact syntax in example template full_class_29.tpl that EZ provides but generally it will look like:

{section name="i" loop=10 sequence=array(1,2,3,4,5) }
<p>$i:sequence}</p>
{/section}

will print out

1
2
3
4
5
1
2
3
4
5

Friday 17 January 2003 5:33:03 pm

> > Is there some way to use an if-else type statement in
> the
> > template files?
> >
> > For example to only show a Heading if there is actually
> > content under the heading. I've tried setting:
> >
> > {let
> >
> list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))}
> >
> > Then wrapping the conditional text in a {section} block
> with
> > the following types of {section} code, but I really
> don't
> > know what they mean or even if I'm on the right track.
> > {section show=$list_count}
> > {section show=eq($list_count)}
> > {section show=and($list_count)}
> >
>
> You are right, you may this syntax:
>
> {section show=gt($list_count,0)}
> ...if ther is some content ...
> {section-else}
> ...if there is no content...
> {/section}
>
> obviously, operators and, not, or, gt, eq are normal logical
> operators, just taking operands inside brackets.
>
> In case you doubt in what meaning your variable takes print
> debug information for yourself, just to know to what value
> to compare:
>
> {$list_count} will print its value on output HTML page.
>
> > Also wanted to know if there is a way to set and display a
>
> > count variable within a loop.
> >
> > like this:
> >
> > {let count=0}
> > {section loop code here}
> > $count
> > {let count=$count+1}
> > {/section}
> >
>
> There is some limit statement in loop, maybe it can help
> you; also loop can work on arrays (look for exact syntax in
> example template full_class_29.tpl that EZ provides but
> generally it will look like:
>
> {section name="i" loop=10 sequence=array(1,2,3,4,5) }
> <p>$i:sequence}</p>
> {/section}
>
> will print out
>
> 1
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5

Thanks for the reply, I got the if-else code working, haven't tried the counting yet. One note on this code:

> {section show=gt($list_count,0)}
> ...if ther is some content ...
> {section-else}
> ...if there is no content...
> {/section}

I found that it didn't work because it appears if the list count is 0, null is actually returned, so the operator can't compare null with 0 and it just displays the content regarless. I ended up just using:

{section show=$list_count}
...if ther is some content ...
{section-else}
...if there is no content...
{/section}

and it worked fine.

Thanks for the help,

Mike

Friday 17 January 2003 6:19:17 pm

> > Is there some way to use an if-else type statement in
> the
> > template files?
> >
> > For example to only show a Heading if there is actually
> > content under the heading. I've tried setting:
> >
> > {let
> >
> list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))}
> >
> > Then wrapping the conditional text in a {section} block
> with
> > the following types of {section} code, but I really
> don't
> > know what they mean or even if I'm on the right track.
> > {section show=$list_count}
> > {section show=eq($list_count)}
> > {section show=and($list_count)}
> >
>
> You are right, you may this syntax:
>
> {section show=gt($list_count,0)}
> ...if ther is some content ...
> {section-else}
> ...if there is no content...
> {/section}
>
> obviously, operators and, not, or, gt, eq are normal logical
> operators, just taking operands inside brackets.
>
> In case you doubt in what meaning your variable takes print
> debug information for yourself, just to know to what value
> to compare:
>
> {$list_count} will print its value on output HTML page.
>
> > Also wanted to know if there is a way to set and display a
>
> > count variable within a loop.
> >
> > like this:
> >
> > {let count=0}
> > {section loop code here}
> > $count
> > {let count=$count+1}
> > {/section}
> >
>
> There is some limit statement in loop, maybe it can help
> you; also loop can work on arrays (look for exact syntax in
> example template full_class_29.tpl that EZ provides but
> generally it will look like:
>
> {section name="i" loop=10 sequence=array(1,2,3,4,5) }
> <p>$i:sequence}</p>
> {/section}
>
> will print out
>
> 1
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5

I'm trying to also use similar logic to display the author of an article only if the show author checkbox has been ticked. I've attempted to use:

{section show=((attribute_view_gui attribute=$node.object.data_map.show_author),yes)}
<p>{attribute_view_gui attribute=$node.object.data_map.author}</p>
{/section}

But I know the syntax is incorrect. The statement: {attribute_view_gui attribute=$node.object.data_map.show_author} returns yes or no, but I can't figure out how to compare this in a {section}statement. Any ideas?

Sunday 19 January 2003 7:54:47 am

> I'm trying to also use similar logic to display the author
> of an article only if the show author checkbox has been
> ticked. I've attempted to use:
>
> {section show=((attribute_view_gui
> attribute=$node.object.data_map.show_author),yes)}
> <p>{attribute_view_gui
> attribute=$node.object.data_map.author}</p>
> {/section}
>
> But I know the syntax is incorrect. The statement:
> {attribute_view_gui
> attribute=$node.object.data_map.show_author} returns yes or
> no, but I can't figure out how to compare this in a
> {section}statement. Any ideas?

I think you forgot "eq" operator:

{section show=eq( (attribute_view_gui attribute=$node.object.data_map.show_author), yes)}

Also, I don't know if "yes" must be quoted.

Wednesday 22 January 2003 7:31:37 pm

&gt; &gt; I'm trying to also use similar logic to display the
&gt; author
&gt; &gt; of an article only if the show author checkbox has been
&gt; &gt; ticked. I've attempted to use:
&gt; &gt;
&gt; &gt; {section show=((attribute_view_gui
&gt; &gt; attribute=$node.object.data_map.show_author),yes)}
&gt; &gt; &lt;p&gt;{attribute_view_gui
&gt; &gt; attribute=$node.object.data_map.author}&lt;/p&gt;
&gt; &gt; {/section}
&gt; &gt;
&gt; &gt; But I know the syntax is incorrect. The statement:
&gt; &gt; {attribute_view_gui
&gt; &gt; attribute=$node.object.data_map.show_author} returns yes
&gt; or
&gt; &gt; no, but I can't figure out how to compare this in a
&gt; &gt; {section}statement. Any ideas?
&gt;
&gt; I think you forgot &quot;eq&quot; operator:
&gt;
&gt; {section show=eq( (attribute_view_gui
&gt; attribute=$node.object.data_map.show_author), yes)}
&gt;
&gt; Also, I don't know if &quot;yes&quot; must be quoted.

I've tried every variation and operator possible to no avail. I don't know if attribute_view_gui
attribute=$node.object.data_map.show_author can be compared in a statement like this, since it has an equals sign, and is normally displayed within {}. I've tried:

{section show=eq( {attribute_view_gui
attribute=$node.object.data_map.show_author}, yes)}

to no avail.

I have noticed one thing though, when:
{attribute_view_gui
attribute=$node.object.data_map.show_author} displays in the template, it doesn't just display the variable value, eZ Publish wraps it in &lt;p class=&quot;box&quot;&gt;&lt;/p&gt; tags. I have edited the file design\standard\templates\content\datatype\view\ezemail.tpl so that only the value displays but still no luck.

Wednesday 22 January 2003 7:58:25 pm

> > I'm trying to also use similar logic to display the
> author
> > of an article only if the show author checkbox has been
> > ticked. I've attempted to use:
> >
> > {section show=((attribute_view_gui
> > attribute=$node.object.data_map.show_author),yes)}
> > <p>{attribute_view_gui
> > attribute=$node.object.data_map.author}</p>
> > {/section}
> >
> > But I know the syntax is incorrect. The statement:
> > {attribute_view_gui
> > attribute=$node.object.data_map.show_author} returns yes
> or
> > no, but I can't figure out how to compare this in a
> > {section}statement. Any ideas?
>
> I think you forgot "eq" operator:
>
> {section show=eq( (attribute_view_gui
> attribute=$node.object.data_map.show_author), yes)}
>
> Also, I don't know if "yes" must be quoted.

I've tried every variation and operator possible to no avail. I don't know if attribute_view_gui
attribute=$node.object.data_map.show_author can be compared in a statement like this, since it has an equals sign, and is normally displayed within {}. I've tried:

{section show=eq( {attribute_view_gui
attribute=$node.object.data_map.show_author}, yes)}

to no avail.

I have noticed one thing though, when:
{attribute_view_gui
attribute=$node.object.data_map.show_author} displays in the template, it doesn't just display the variable value, eZ Publish wraps it in <p class="box"></p> tags. I have edited the file design\standard\templates\content\datatype\view\ezemail.tpl so that only the value displays but still no luck.

Wednesday 22 January 2003 11:35:57 pm

> > > I'm trying to also use similar logic to display
> the
> > author
> > > of an article only if the show author checkbox has
> been
> > > ticked. I've attempted to use:
> > >
> > > {section show=((attribute_view_gui
> > >
> attribute=$node.object.data_map.show_author),yes)}
> > > <p>{attribute_view_gui
> > >
> attribute=$node.object.data_map.author}</p>
> > > {/section}
> > >
> > > But I know the syntax is incorrect. The
> statement:
> > > {attribute_view_gui
> > > attribute=$node.object.data_map.show_author}
> returns yes
> > or
> > > no, but I can't figure out how to compare this in
> a
> > > {section}statement. Any ideas?
> >
> > I think you forgot "eq" operator:
> >
> > {section show=eq( (attribute_view_gui
> > attribute=$node.object.data_map.show_author), yes)}
> >
> > Also, I don't know if "yes" must be quoted.
>
> I've tried every variation and operator possible to no
> avail. I don't know if attribute_view_gui
> attribute=$node.object.data_map.show_author can be compared
> in a statement like this, since it has an equals sign, and
> is normally displayed within {}. I've tried:
>
> {section show=eq( {attribute_view_gui
> attribute=$node.object.data_map.show_author}, yes)}
>
> to no avail.
>
> I have noticed one thing though, when:
> {attribute_view_gui
> attribute=$node.object.data_map.show_author} displays in the
> template, it doesn't just display the variable value, eZ
> Publish wraps it in <p
> class="box"></p> tags. I have edited the
> file
> design\standard\templates\content\datatype\view\ezemail.tpl
> so that only the value displays but still no luck.

Hi Mike

The {attribute_view_gui ... } seems to be designed to display the attribute of the object not return the actual value of it.

I suspect that there may be another template function to allow this access (It may not exist as yet). The rest of your template code looks find we just need to find the right function happy.gif Emoticon

Bruce

Thursday 23 January 2003 1:13:35 pm

>
> {section show=eq( {attribute_view_gui
> attribute=$node.object.data_map.show_author}, yes)}
>

Try this:

{section show=eq($node.object.data_map.show_author.content, "1"blunk.gif Emoticon}

Thursday 23 January 2003 5:26:45 pm

> >
> > {section show=eq( {attribute_view_gui
> > attribute=$node.object.data_map.show_author}, yes)}
> >
>
>
> Try this:
>
> {section show=eq($node.object.data_map.show_author.content,
> "1"blunk.gif Emoticon}

Sergei,

Thank you very much, that worked.

Mike

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from