Jump to content

{if} for truncate product name


Recommended Posts

Hi all,

I have 'small' problem. I am new with doing some advanced functions in presta, and I wanted to create function {if} for product.name truncate. But this one doesn`t work. 

 

Below is the code:

 

{if $product.name|truncate >20}
<h2 class="featured-product-title">
<a href="{$product.link}" title="{$product.name|truncate:50:'...'|escape:'htmlall':'UTF-8'}">
{$product.name|truncate:40:'...'|escape:'htmlall':'UTF-8'}
</a>
</h2>
{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p class="price_container">
<span class="price">
{if !$priceDisplay}
{convertPrice price=$product.price}
{else}
{convertPrice price=$product.price_tax_exc}
{/if}
</span>
</p>
{else}
<div style="height:41px;"></div>
{/if}
{if ($product.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $product.available_for_order AND !isset($restricted_country_mode) AND $product.minimal_quantity == 1 AND $product.customizable != 2 AND !$PS_CATALOG_MODE}
{if ($product.quantity > 0 OR $product.allow_oosp)}
<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pwextendhomefeature'}">{l s='Add to cart' mod='pwextendhomefeature'}</a>
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}
{else}
<span class="exclusive">
{l s='Out of stock' mod='pwextendhomefeature'}
</span>
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}
{/if}
{else}
{*<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pwextendhomefeature'}">{l s='Add to cart' mod='pwextendhomefeature'}</a>*}
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}

{/if}
{else}
<h2 class="featured-product-title">
<a href="{$product.link}" title="{$product.name|truncate:50:'...'|escape:'htmlall':'UTF-8'}">
{$product.name|truncate:40:'...'|escape:'htmlall':'UTF-8'}
</a>
</h2>
{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p class="price_container">
<span class="price">
{if !$priceDisplay}
{convertPrice price=$product.price}
{else}
{convertPrice price=$product.price_tax_exc}
{/if}
</span>
</p>
{else}
<div style="height:41px;"></div>
{/if}
{if ($product.id_product_attribute == 0 OR (isset($add_prod_display) AND ($add_prod_display == 1))) AND $product.available_for_order AND !isset($restricted_country_mode) AND $product.minimal_quantity == 1 AND $product.customizable != 2 AND !$PS_CATALOG_MODE}
{if ($product.quantity > 0 OR $product.allow_oosp)}
<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pwextendhomefeature'}">{l s='Add to cart' mod='pwextendhomefeature'}</a>
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}
{else}
<span class="exclusive">
{l s='Out of stock' mod='pwextendhomefeature'}
</span>
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}
{/if}
{else}
{*<a class="exclusive ajax_add_to_cart_button" rel="ajax_id_product_{$product.id_product}" href="{$link->getPageLink('cart')}?qty=1&id_product={$product.id_product}&token={$static_token}&add" title="{l s='Add to cart' mod='pwextendhomefeature'}">{l s='Add to cart' mod='pwextendhomefeature'}</a>*}
{*<a class="lnk_more" href="{$product.link}" title="{l s='View' mod='pwextendhomefeature'}">{l s='View' mod='pwextendhomefeature'}</a>*}
<div style="height: 32px"></div>
{/if}

{/if}

 

I wanted to check if the product name is longer than>20, I wanted to show full product name. If it was <20, I wanted to display full product name but with some space below it so I added:

<div style="height: 32px"></div>

 

 

Why? Beacuse If I change truncate to full product name, I get something like this:

post-746061-0-81701300-1418164818_thumb.jpg

 

Theme I am using is kronan: http://themeforest.net/item/kronan-responsive-prestashop-theme/6618981

 

I just want to make all windows in same size.

Any suggestions?

Regards,
Rafa

Link to comment
Share on other sites

  • 1 month later...

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...