Forums / Setup & design / Very strange on if query

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Very strange on if query

Author Message

Toms King

Tuesday 29 August 2006 4:14:43 am

On a template, I wanna to catch the value of $p, so I define at the begining

{if eq($p,'')}
  { set $p = 1 } 
      Testing
 {/if}

for if cannot catch $p, $p will be set the default value as 1, and print Testing

and when I run the template, testing was printed, but the value of $p haven't been set, why?.....

and when I add some code as

{if eq($p,'')}
  { set $p = 1 } 
      Testing


 {/if}

{if eq($p,'')}
  
      Testing2


 {/if}

only Testing 2 was print, so strange

the full code of this template is attached

{if eq($p,'')}

  { set $p = 1 } 
      Testing


 {/if}
             
{if eq($p,'')}
  
      Testing2


 {/if}


{let news=fetch(content,list,hash(parent_node_id,73,
                                       limit, 10, 
                                       sort_by,  array( published, false() ), 
                                       offset,$view_parameters.offset,
                                       class_filter_type,include,
                                       class_filter_array,array('17'))) 
$pages = ceil(div(count($news),3))

}




Pages: <
{for 1 to $pages as $page}

<a href={concat('content/news_display?p=',$page)|ezurl()}>{$page}</a>

{/for} > Page: {$p}    </br>

  {if ge(count($news),mul($pages,3))}

 {for sub(mul($p,3),3) to sub(mul($p,3),1) as $index}
               <a href={$news[$index].url_alias|ezurl}>  {$news[$index].object.data_map.title.content|wash}  </a></br>
             {$news[$index].object.data_map.intro.content|wash}  </br></br>
                 {/for}

  {else}
{for sub(mul($p,3),3) to sub(count($news),1) as $index}
               <a href={$news[$index].url_alias|ezurl}>  {$news[$index].object.data_map.title.content|wash}  </a></br>
             {$news[$index].object.data_map.intro.content|wash}  </br></br>
                 {/for}

 {/if}

Christian Johansen

Tuesday 29 August 2006 5:59:54 am

You need the is_set function. Change this:

{if eq($p,'')}
{set $p = 1}
Testing
{/if}

To this:

{if not( is_set( $p ) )}{def $p=1}{/if}

If it is likely that $p exists but is empty to this:

{if not( is_set( $p ) )}{def $p=1}{/if}
{if $p|eq( '' )}{set $p=1}{/if}