Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Prestashop 1.7 and layout

 
Post new topic   Reply to topic    Smarty Forum Index -> Frameworks
View previous topic :: View next topic  
Author Message
taniacr
Smarty n00b


Joined: 28 Nov 2018
Posts: 1

PostPosted: Wed Nov 28, 2018 5:35 pm    Post subject: Prestashop 1.7 and layout Reply with quote

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
View user's profile Send private message
Revover
Smarty n00b


Joined: 21 Nov 2018
Posts: 3

PostPosted: Fri Nov 30, 2018 9:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
bsmither
Smarty Pro


Joined: 20 Dec 2011
Posts: 197
Location: West Coast

PostPosted: Sat Dec 01, 2018 12:32 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Frameworks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP