Jump to content

[solved] Conditional If Statements In .tpl?


Recommended Posts

I am playing around with the layout of some pages and want to change what is seen based on a particular variable. for example: i want to display some text on the shipping page if you are from a particualr zone and display other text if you are not from that zone.


so i was looking at order-carrier.tpl and want to put an if statement that will for example show "Hello There if from ZONE1" else it would show "Goodbye" if they were not from that zone.


it seems pretty simple but i've been struggling with the php code for determining how i should tackel this.


if adress zone = USA

display this


display that



do i have to use a javascript function to first get the value?

Link to comment
Share on other sites

Go to backoffice > advanced parameters and set the following:


Template cache: force recompilation

cache: no

Debug console: Always open console


The refresh the page, and you will get a super helpfull new window pop open with all the loaded template files, and assigned variables. Check the variable you want is there (im very new to presta, so have no idea what is is called im afraid) and if it is you can do the following simple if statement (replacing $var with the correct smarty variable):



{if $var eq 'USA'}

<p>hello USA</p>

{elseif $var eq 'UK'}

<p>Hello UK</p>


<p>So where are you from then?</p>



see the smarty site for more help: http://www.smarty.net/docsv2/en/language.function.if.tpl

Link to comment
Share on other sites

Hi - I tried this in the address.tpl under the country drop-down:



{if $id_country == '24'}


<p class="warning">helloAustralia</p>

{elseif $id_country eq '17'}

<p class="warning">Hello UK</p>


<p class="warning">So where are you from then?</p>



Only ever get the else statement showing!


What am i doing wrong?

Link to comment
Share on other sites

so in order-carrier.tpl the following works: i think i could have used ->id or ->id_reference but every time you make a change to the carrier i think this number changes in the database.


{if $carrier.instance->name == 'Displayed Name of my Shipper'}

{l s='DisplayOne thing'}


{l s='Display Something Else'}



when i try to use that code in order-payment.tpl it does not work. i imagine that i need to somehow involve that variable in that tpl file or something. i am using one page checkout. what i want to happen is to only display the pay modules pay with paypal module and paypal pro module and nothing else, without disabling other payment systems. i installed the universal pay systems and want that displayed without the above two when a particular carrier is selected.


also, can anyone shed some light on why i used two == signs, i did some reading but figured that one should have worked as opposed to two.

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...