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}

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 20:50:13
Script start
Timing: Jan 18 2025 20:50:13
Module start 'layout'
Timing: Jan 18 2025 20:50:13
Module start 'content'
Timing: Jan 18 2025 20:50:13
Module end 'content'
Timing: Jan 18 2025 20:50:13
Script end

Main resources:

Total runtime0.0298 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 589.0469152.6250
Module start 'layout' 0.00800.0042 741.671939.4453
Module start 'content' 0.01220.0152 781.117289.2422
Module end 'content' 0.02740.0023 870.359430.3047
Script end 0.0297  900.6641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003010.1568140.0002
Check MTime0.00155.1269140.0001
Mysql Total
Database connection0.00134.311910.0013
Mysqli_queries0.003210.778130.0011
Looping result0.00000.053610.0000
Template Total0.00175.710.0017
Template load0.00093.039010.0009
Template processing0.00082.675510.0008
Override
Cache load0.00061.907010.0006
General
dbfile0.003411.557080.0004
String conversion0.00000.020840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs