Page 1 of 1

Conditional Template - Smarty and Arrays

Posted: Sun May 30, 2010 8:48 pm
by tobre
I would like to conditionally hide elements in a template based on whether or not a page-alias is in a predefined array, like so...

Code: Select all

{if (in_array($page_alias,$someArray))}
  show this
{/if}
My problem is: How and where would I best define that array?

Code: Select all

$someArray=array( 'alias1', 'alias2', 'alias3','alias4' );

--- addendum ---
??? How is working with arrays in templates not a valid topic for the development discussions board?

Re: Conditional Template - Smarty and Arrays

Posted: Tue Jun 15, 2010 9:29 pm
by kermit
the most basic solution would be a udt....

Code: Select all

// assignarray
global $gCms;
$myArray = array("index","do-dads","gizmos","some-other-page");
$smarty->assign('alternatelayout',$myArray);
you could get fancy and pass a parameter containing page aliases to populate the array.. i'll leave that up to you.

then in your template or page data:

Code: Select all

{assignarray}
followed by the smarty logic

Code: Select all

{if in_array($page_alias,$alternatelayout)}
 do this or show that
{else}
 otherwise do this instead
{/if}
to examine the array contents in smarty use

Code: Select all

{$alternatelayout|@print_r}