elorac Posted March 29, 2014 Share Posted March 29, 2014 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 More sharing options...
loulou66 Posted March 29, 2014 Share Posted March 29, 2014 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 Link to comment Share on other sites More sharing options...
elorac Posted March 30, 2014 Author Share Posted March 30, 2014 (edited) 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 March 30, 2014 by elorac (see edit history) Link to comment Share on other sites More sharing options...
loulou66 Posted March 30, 2014 Share Posted March 30, 2014 Hi ok 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 More sharing options...
elorac Posted March 30, 2014 Author Share Posted March 30, 2014 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 More sharing options...
Recommended Posts