Jump to content

if/else


Recommended Posts

What I'm trying to do is load a different category.tpl depending on which category is displayed.

I tried various combinations but nothing works.

essentially:

if category is birds

$smarty->display(_PS_THEME_DIR_.'category_birds.tpl');

elseif category is snakes

$smarty->display(_PS_THEME_DIR_.'category_snakes.tpl');

elseif everything else

$smarty->display(_PS_THEME_DIR_.'category.tpl');



Sorry for the questions. I do know PHP and spend a lot of time in WordPress but this is slightly different to what I'm used to.

Thanks.

Link to comment
Share on other sites

Try the following:

if ($_GET['id_category'] == 2)
  $smarty->display(_PS_THEME_DIR_.'category_birds.tpl');
else if ($_GET['id_category'] == 3)
  $smarty->display(_PS_THEME_DIR_.'category_snakes.tpl');
else
  $smarty->display(_PS_THEME_DIR_.'category.tpl');



where 2 is the id of the birds category and 3 is the id of the snakes category.

Link to comment
Share on other sites

I think I'm getting my curlies mixed up as that's producing errors.

I tried:

{if ($_GET['id_category'] == 2)}
  $smarty->display(_PS_THEME_DIR_.'category_birds.tpl');
{else if ($_GET['id_category'] == 3)}
  $smarty->display(_PS_THEME_DIR_.'category_snakes.tpl');
{else}
  $smarty->display(_PS_THEME_DIR_.'category.tpl'); 
{/if}



Not right!

Link to comment
Share on other sites

  • 10 months later...
{if ($_GET['id_category'] == 2)}
  $smarty->display(_PS_THEME_DIR_.'category_birds.tpl');
{else if ($_GET['id_category'] == 3)}
  $smarty->display(_PS_THEME_DIR_.'category_snakes.tpl');
{else}
  $smarty->display(_PS_THEME_DIR_.'category.tpl'); 
{/if} 


in tpl files, solution is this :

{if ...}
...
{elseif ...}
...
{else}
...
{/if}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...