Jump to content

[SOLVED] How can I truncate product title if parent has class?


kingsinnersoul

Recommended Posts

Hello,

I am tring to have two different views which change on button click. I want to display different title width for each view. I know I can do the following in JS

{literal}
  <script type="text/javascript">
   if ($('ul#product_list').hasClass('GRID_VIEW')){
	{$product.name|escape:'htmlall':'UTF-8'|truncate:35:'...'}</a></h3>
   }
   else if ($('ul#product_list').hasClass('LIST_VIEW')){
	{$product.name|escape:'htmlall':'UTF-8'|truncate:75:'...'}</a></h3>
   }
  </script>
  {/literal}

but id did not display the title at all.

 

Is there a way to use smarty in order to achieve the above desired result?

 

THANK YOU.

Link to comment
Share on other sites

No experience with it, but can't you use php function get_class($classVariable) here??

 

Other option might be to just to create a var that holds the status of the viewtype and toggle it when pressing the button, as well as truncate according to ViewType equals 0 (i.e. Gridview) or 1(i.e. listview)

 

My 2 cents,

pascal

Link to comment
Share on other sites

I kinda solved it by using something as follows:

[/size]
<div class="grid_checker">
  {if $subcategory.description}
   <p class="cat_desc">{$subcategory.description|truncate:250}</p>
  {/if}
 </div>
 <div class="list_checker">
  {if $subcategory.description}
   <p class="cat_desc">{$subcategory.description}</p>
  {/if}
 </div>

the parent DIV was changing class if it was grid or list. And then in css I added that grid_checker or list_checker was set to display:hidden or display:block... It does the trick - but it is not efficient as it calls twice for the same thing. I just wanted somehow to add the "truncate:250" if the parent div has class or not. oh well... (thanks for the cents :-)

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