Jump to content

if statemant in the product-list file


Recommended Posts

Hello,

 

I have inserted :

 

 {if $product->id == 12}

<p class="redtxt" style="padding:5px 0 0 0; font-size:15px;"><strong>Delivery in 24h</strong></p>

{/if}

 

in the product.tpl file. And code WORKS great.

 

After that, I have tried to put the same code in the product-list.tpl file, but if statemant does not work.
( without {if} statemant, text shows on every product on the homepage )

 

Code is:

 

<div class="right-block">
                        <h5 itemprop="name">
                            {if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}
                            <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" >
                                <span class="list-name">{$product.name|truncate:60:'...'|escape:'html':'UTF-8'}</span>
                                <span class="grid-name">{$product.name|truncate:30:'...'|escape:'html':'UTF-8'}</span>
                            </a>
                            <div>{if $product->id == 12}
                                <p class="redtxt" style="padding:5px 0 0 0; font-size:15px;"><strong>Delivery in 24h</strong></p>
                        {/if}</div>
                        </h5>
 
Why code works in product.tpl file, and it dont work in product-list.tpl?
Does any1 have clue, how to put {if} statemant and to show text under product image ONLY for product with ID 12
 
Thank you ALOT,
Nikola
 
Link to comment
Share on other sites

Hi!

In product-list.tpl, the variable wich refers to the products, works differently.

 

You need to change tha call to the product ID to this: 


$product.id

The code in product-list.tpl should be like this:

<h5 itemprop="name">
                            {if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}
                            <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" >
                                <span class="list-name">{$product.name|truncate:60:'...'|escape:'html':'UTF-8'}</span>
                                <span class="grid-name">{$product.name|truncate:30:'...'|escape:'html':'UTF-8'}</span>
                            </a>
                            <div>{if $product.id == 12}
                                <p class="redtxt" style="padding:5px 0 0 0; font-size:15px;"><strong>Delivery in 24h</strong></p>
                        {/if}</div>
                        </h5>

I think that this is the problem.

Edited by metal1616 (see edit history)
Link to comment
Share on other sites

Try with 

<div class="right-block">
                        <h5 itemprop="name">
                            {if isset($product.pack_quantity) && $product.pack_quantity}{$product.pack_quantity|intval|cat:' x '}{/if}
                                <a class="product-name" href="{$product.link|escape:'html':'UTF-8'}" title="{$product.name|escape:'html':'UTF-8'}" itemprop="url" >
                                <span class="list-name">{$product.name|truncate:60:'...'|escape:'html':'UTF-8'}</span>
                                <span class="grid-name">{$product.name|truncate:30:'...'|escape:'html':'UTF-8'}</span>
                                </a>
                                {if $product.id == 12}
                                    <p class="redtxt" style="padding:5px 0 0 0; font-size:15px;"><strong>Delivery in 24h</strong></p>
                                {/if}
                            {/if}
                        </h5>

Note in product.tpl variable $product is Object so you use ->. In product list is Array so you access properies with . 

 

Also this is not good way, to hard code it like that. Try to use Availabily settings http://doc.prestashop.com/display/PS16/Managing+Products#ManagingProducts-AvailabilitySettings

  • Like 1
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...