I have a little smarty trouble here, as a non programmer.
I have an extra field for the products, which when activated means the product is not available anymore (vergriffen) and therefore the "add to cart" button is not displayed on that product. The code in the products list template is s follows:
{if $entry->fields.vergriffen == true}
vergriffen
{else}
{Cart2 sku=$entry->sku} <div class="preis">CHF {$entry->price|number_format:2}</div>
{/if}
In my understanding this will show the text "vergriffen" if the field value is = true. And in all other cases it shows the button
And it works so far. BUT, only if there is no other value present. There have been cases where once the field has been activated and deactivated and the database ends up containing "false" for this product. Strange that in that case it also displays "vergriffen", but it must show the "add to cart" button.
Only if I delete the entry in the database, it works properly again. Not even leaving it blank works.
So what did I wrong in the smarty code? I mean, if its not "true" but in any other case (blank, false, dummydumb or whatever) the "else" statement should take effect. Or not?
Thanks for any enlightment on the matter.
Thom
[SOLVED] Products, smarty if value
[SOLVED] Products, smarty if value
Last edited by thomahawk on Fri Apr 11, 2014 8:43 am, edited 1 time in total.
Re: Products, smarty if value
It seems that the field is a text field so "false" will validate as true...
Maybe
Maybe
Code: Select all
{if isset($entry->fields.vergriffen) && $entry->fields.vergriffen == 'true'}"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Re: Products, smarty if value
Hi Jo. Thanks for the input.
But unfortunately it does not work. Your code makes all products available.
Backgroud information: Most products have no entry for this field in the database, because the items got registered in "Products" but the "vergriffen" field never used. Two have the entry "true" (because they are not available anymore), one has the entry "false" (I did set it to true once and then deactivated the "vergriffen" field again, this results in "false" stored in the database).
I see what you mean, I have to address the value of that field. I thought my original code did that, but obviously thats not the case. I also tried {if $entry->fields.vergriffen == 'true'} but this produces page error.
But unfortunately it does not work. Your code makes all products available.
Backgroud information: Most products have no entry for this field in the database, because the items got registered in "Products" but the "vergriffen" field never used. Two have the entry "true" (because they are not available anymore), one has the entry "false" (I did set it to true once and then deactivated the "vergriffen" field again, this results in "false" stored in the database).
I see what you mean, I have to address the value of that field. I thought my original code did that, but obviously thats not the case. I also tried {if $entry->fields.vergriffen == 'true'} but this produces page error.
Re: Products, smarty if value
The error message could be helpful. Make sure to test the page in the same browser you logged in to cms.I also tried {if $entry->fields.vergriffen == 'true'} but this produces page error.
<pre>{$entry->fields.vergriffen|print_r}</pre> should print out useful information about the field. Then you know what you should check for (e.g. boolean or string)
try (assumes a boolean):
Code: Select all
{if isset($entry->fields.vergriffen) && $entry->fields.vergriffen->value}Code: Select all
{if isset($entry->fields.vergriffen) && $entry->fields.vergriffen->value == 'true'}Re: Products, smarty if value
Great!
{if isset($entry->fields.vergriffen) && $entry->fields.vergriffen->value == 'true'}
This has solved the problem perfectly!
Thank you very much, velden (once again
Thom
{if isset($entry->fields.vergriffen) && $entry->fields.vergriffen->value == 'true'}
This has solved the problem perfectly!
Thank you very much, velden (once again
Thom


