A slightly strange one, but I’m using an ecommerce platform called CS-Cart which uses smarty for it’s templating language. It has a smarty debug console which allows me to see which variables the current page is using.
For example, here is an array that is being used (I have shortened this for the example):
Appearance => Array (33)
products_per_page => "10"
admin_products_per_page => "10"
admin_elements_per_page => "10"
columns_in_products_list => "3"
default_products_sorting => "price"
I would like to be able to assign a different value to default_products_sorting => "price"
I plan to do this in the header of my document as it will be included in an IF statement whereby the variable is only changed if certain conditions are true.
Is this even possible in smarty? (without the use of PHP) and if so any ideas on how this could be achieved? I’ve scoured Google but so far turned up a blank.
Any help is much appreciated.
You can change the variable like this
And after this line, if you use
{$Appearance.default_products_sorting}you should get the new value.I just checked and it worked.
You should change it at the top of your smarty template, so that any code that is using this variable get the updated value.
Looks like the above method doesn’t work for
arrays. You can consider using the custom function from this link http://www.smarty.net/forums/viewtopic.php?t=7201&highlight=create+array