Jump to content

Smarty Template Question


Recommended Posts

Hi, I have a new variable in my template and I want to put an if statement around it.  For example:

 

{if $My Var != ''}

  Some code here...

  {l s='My Var' mod='blockpermanentlinks'}

  More Code here...

{/if}

 

So... How do I write that IF statement?  Obviously mine is incorrect.  All I want to do is write a smarty if statement to display that block of code if the variable in the languages is not blank for 'My Var'.

 

Thanks

Link to comment
Share on other sites

HI

 

dunno if i understand but

{if isset($myvar)}

/*if $myvar exist and $myvar not = 0 */

 Some code here...
  {l s='My Var' mod='blockpermanentlinks'}
  More Code here...
{/if}

i hope that help you

 

@++

 

Loulou66

 

Maybe I wasn't explaining clearly.  First off, this is for Prestashop 1.6 (not sure if that matters).  In a Prestashop smarty template, to create a variable automatically and echo it, you would do something like this:

    {l s='My Var' mod='blockpermanentlinks'}

You will see in the languages section (under localization -> translations) in the admin area under the installed modules "blockpermanentlinks", it will create an entry called "My Var".  You can then edit the contents of "My Var" in the admin area.  Following so far?

 

Ok...  So, what I need is the smarty code to check that new variable or entry of "My Var" and see if it's empty or not, on that same page. If it IS empty or if "My Var" does not exist, then echo the block of code between the IF statement.

 

Maybe I need something like this instead?:

 

{assign var="foo" value=(how get the contents of "My Var"?) }

{if $foo != ''}
   {l s='My Var' mod='blockpermanentlinks'}
{/if}

 

I just don't know how to retrieve the value of "My Var".  Maybe I'm going about this wrong?

 

 

Hope that makes a little more sense.  Thanks for your help!

Edited by elorac (see edit history)
Link to comment
Share on other sites

Hi

 

ok :P

 

the best is

 

in blockpermanetlinks.php define in fonction hookTop

 

if (conditions) you must define the conditions

$myvar = 1; (not empty) or $myvar = true;

else

$myvar = 0; (empty) or $myvar = false;

 

$this->context->smarty->assign('myvar' , $myvar); ( for ps 1.5++/1.6)

$this->smarty->assign('myvar' , $myvar); (for PS 14)

 

then on your tpl

{if isset($myvar)}  

{l s='bla bla bla' mod='blockpermanentlinks'}

 

or

 

{if ($myvar == 1)}  or {if ($myvar == "true")}  

{l s=''bla bla bla' mod='blockpermanentlink

 

@++

 

Loulou66

 

Link to comment
Share on other sites

Thanks Loulou66, I think we are on the right track.  Now I just need to know how to pull the value of the language variable in that php file using Presta conventions.  So for example, in the lang en.php file you might see this:

 

$_MODULE['<{blockpermanentlinks}prestashop>blockpermanentlinks_c661cf76442d8d2cb318d560285a2a57'] = 'Contact form';

 

So the big question is, how do I get the value 'Contact form' in the above example using Prestashop functions?  I'm guessing there is some simple way to do this?

 

Thanks!  :)

Link to comment
Share on other sites

×
×
  • Create New...