Jump to content

[SOLVED] How can I use different format according to different category?


Recommended Posts

I am using 3 columns, default template. I would like to make category page in category 3, 4, and 5 with no left and right columns, and the rest of the category pages use default format which include left and right columns.

Thank you for the help.

Link to comment
Share on other sites

Smarty if statements to the rescue yet again!

Modify header.tpl in your theme's directory and modify the body tag and change it from:

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>



to:

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $smarty.get.id_category == 3 OR $smarty.get.id_category == 4 OR $smarty.get.id_category == 5} class="no_columns"{/if}>



and the left column code from:

<!-- Left -->

   {$HOOK_LEFT_COLUMN}



to:

{if $smarty.get.id_category != 3 AND $smarty.get.id_category != 4 AND $smarty.get.id_category != 5}
   <!-- Left -->

       {$HOOK_LEFT_COLUMN}

{/if}



and change the right column section in footer.tpl in your theme's directory from:

<!-- Right -->

               {$HOOK_RIGHT_COLUMN}



to:

{if $smarty.get.id_category != 3 AND $smarty.get.id_category != 4 AND $smarty.get.id_category != 5}
   <!-- Right -->

       {$HOOK_RIGHT_COLUMN}

{/if}



Then add the following to global.css to increase the width of the center column when the left and right columns are missing:

body.no_columns #center_column
{
  width: 960px;
}



Change 960px to whatever width is appropriate.

  • Like 1
Link to comment
Share on other sites

I just tested the code I wrote above and it is working on my test site. Are you sure you copied it right? I've attached a screenshot of what it looks like on my site.


Sorry, it was not working until I cleared my Cache on my browser. :down: Sorry for wasting your time. Thank you very much.
Link to comment
Share on other sites

  • 1 month later...
I want to achieve sort like result, but use a different .tpl file for specific category (which is a stripped version of default product list with just product name, price and order button).
Is it possible with smarty?

The same question as Sanis's
Link to comment
Share on other sites

  • 5 months later...
I want to achieve sort like result, but use a different .tpl file for specific category (which is a stripped version of default product list with just product name, price and order button).
Is it possible with smarty?

The same question as Sanis's

The same question as you two ^^

Is it possible to use a specific template for each category ?

Thanks !
Link to comment
Share on other sites

To call a different product list tpl file depending on the category, you could change line 55 of category.tpl from:

{include file=$tpl_dir./product-list.tpl products=$products}



to:

{if $smarty.get.id_category == 2}
{include file=$tpl_dir./product-list2.tpl products=$products}
{elseif $smarty.get.id_category == 3}
{include file=$tpl_dir./product-list3.tpl products=$products}
{/if}



Then create product-list2.tpl and product-list3.tpl.

Link to comment
Share on other sites

I thought it a bit, and came up with a different approach : apply a template depending on the page url.

Using url rewrite, have a reference to a template in the url, like http://www.configurateurvisuel.fr/47-t-shirts-isant-v2- where isant-v2 is your reference

my mod will apply the appropriate template (depending on your own set of rules)

Heres the french topic, the code is commented in english, feel free to ask if it's not clear enough.

http://www.prestashop.com/forums/viewthread/68565/modules_tiers/mod_template_dynamique__utilisez_plusieurs_themes_sur_votre_boutique

Regards
mika

Link to comment
Share on other sites

  • 9 months later...
To call a different product list tpl file depending on the category, you could change line 55 of category.tpl from:

{include file=$tpl_dir./product-list.tpl products=$products}



to:

{if $smarty.get.id_category == 2}
{include file=$tpl_dir./product-list2.tpl products=$products}
{elseif $smarty.get.id_category == 3}
{include file=$tpl_dir./product-list3.tpl products=$products}
{/if}



Then create product-list2.tpl and product-list3.tpl.



----------------------------------------------------------------------------

Amazing, thank you, but how to control templates at frontend. User comes to shop, see category and have ability to change category view from list to grid view? Thank you. It would be really nice feature in future releases of prestashop.
Link to comment
Share on other sites

  • 9 months later...

To call a different product list tpl file depending on the category, you could change line 55 of category.tpl from:

 

{include file=$tpl_dir./product-list.tpl products=$products}

 

to:

 

{if $smarty.get.id_category == 2}
{include file=$tpl_dir./product-list2.tpl products=$products}
{elseif $smarty.get.id_category == 3}
{include file=$tpl_dir./product-list3.tpl products=$products}
{/if}

 

Then create product-list2.tpl and product-list3.tpl.

 

I find this solution to be slightly daunting for the developer when the customer wants to create multiple pages full of products.

 

rocky, would you mind providing a solution where the conditional statement is applied somewhere else which also calls a different template file dynamically (by dynamically, I mean there's no need to constantly update the categories' id if there are new pages created)? Maybe apply it to the subcategories and all the subcategories have a different product list template (with its own CSS and JS obviously) or simply call the same product list template but extend the template while hiding the original content?

 

I'll attempt a solution in the meantime, but may not get too far with the dynamic calls.

Link to comment
Share on other sites

  • 1 month later...

Smarty if statements to the rescue yet again!

 

Modify header.tpl in your theme's directory and modify the body tag and change it from:

 

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>

 

to:

 

<body {if $page_name}id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}{if $smarty.get.id_category == 3 OR $smarty.get.id_category == 4 OR $smarty.get.id_category == 5} class="no_columns"{/if}>

 

and the left column code from:

 

<!-- Left -->

{$HOOK_LEFT_COLUMN}

 

to:

 

{if $smarty.get.id_category != 3 AND $smarty.get.id_category != 4 AND $smarty.get.id_category != 5}
<!-- Left -->


	{$HOOK_LEFT_COLUMN}


{/if}

 

and change the right column section in footer.tpl in your theme's directory from:

 

<!-- Right -->


			{$HOOK_RIGHT_COLUMN}


 

to:

 

{if $smarty.get.id_category != 3 AND $smarty.get.id_category != 4 AND $smarty.get.id_category != 5}
<!-- Right -->


	{$HOOK_RIGHT_COLUMN}


{/if}

 

Then add the following to global.css to increase the width of the center column when the left and right columns are missing:

 

body.no_columns #center_column
{
  width: 960px;
}

 

Change 960px to whatever width is appropriate.

 

 

Thank you very much. with your tip i was able to solve my problem by replacing id_category with id_cms and is working like a charm

 

Thank you

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

  • 7 months later...
×
×
  • Create New...