|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
taniacr Smarty n00b
Joined: 28 Nov 2018 Posts: 3
|
Posted: Wed Nov 28, 2018 5:35 pm Post subject: Prestashop 1.7 and layout |
|
|
Hello,
I want to apologise if i'm not asking this in the right place.
I'm trying to do a simple thing but I'm not very smarty myself (insert laughter here).
Here's what i'm trying to do in a layout:
If category_cover is defined show that or else show the category_cover defined for Home category.
What I've got so far is:
Code: |
{if isset($category.image.large)}
<div class="category-cover">
<img src="{$category.image.large.url}" alt="{$category.image.legend}">
</div>
{else}
<div class="category-cover">
Show here Category ID = 1 Cover
</div>
{/if}
|
How do I tell prestashop to show the categoryID=1 large image?
Thank you in advance |
|
Back to top |
|
Revover Smarty n00b
Joined: 21 Nov 2018 Posts: 3
|
Posted: Fri Nov 30, 2018 9:31 pm Post subject: |
|
|
I'm unsure what are you exactly asking about. If you have variable categoryID that has been passed to Smarty, then it's like that
Code: | {if $categoryID==1}{$categoryID}{/if} |
If ID is a part of category then
Code: | {if $category.id==1}{$category.id}{/if} |
However, maybe in you case you need either 2nd variable or you want to place both covers in an array. It would be helpful to know what's in your variables. If you're unsure what's passed to Smarty use debug (https://www.smarty.net/docs/en/language.function.debug.tpl) in your .tpl file. |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Sat Dec 01, 2018 12:32 am Post subject: |
|
|
I would try this:
Code: | <div class="category-cover">
<img src=
"{$category.image.large.url|default:'url_of_cat_id_1_large_image'}"
alt=
"{$category.image.legend|default:'default_legend'}"
>
</div>
|
This has hard-coded default values - and doing hard-coded stuff assumes you can't make this decision in the PHP that populates $category.
See the default modifier:
https://www.smarty.net/docs/en/language.modifier.default.tpl |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|