A
A
Alexey Ermolaev2015-08-13 14:46:06
Smarty
Alexey Ermolaev, 2015-08-13 14:46:06

How to display condition correctly in Smarty template?

The situation is as follows: a site on Webasyst. The site has several categories of products. One has a sidebar with sorting options on the left and a list of products on the right. The other has just a list of its subcategories without a sidebar.
Both categories use the same template for displaying products. In the one with the sidebar, the block width is 77%. Accordingly, in the other the same width. It is necessary that on the page of the category without a sidebar, the list of products would stretch to the full width of the page. Adding an additional class would not solve the problem, since the same class would appear on other pages, because there is only one template. Therefore, it was decided to display blocks through a condition, on one page of divs with one ID, on the other with another. I write the condition in the template like this:

{if $wa->app() == 'shop' && $page.url == '/category/avtochekhly-po-modelyam/'}

<div id="product-list">

{else}

<div id="cat-list">

{/if}

There is no effect, except that the ID changes to the one in else on the pages of all categories.
Therefore, the question is: how to write this condition correctly?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2015-08-13
@ermolaevalexey

I don't know what you have stored in $page, but you can try this
only probably without the last slash

A
Alexander Reshetnyak, 2018-07-11
@Vampireos

Did it like this:

{* ВЫВОДИМ НА СТРАНИЦЕ ПРОДУКТА *}
{if strpos($smarty.server.REQUEST_URI,"/show-product/") !== false}

  контент

{* ВЫВОДИМ НА ГЛАВНОЙ *}
{elseif strpos($smarty.server.REQUEST_URI,"/base/") !== false}
 
  контент  

{* ВЫВОДИМ НА СТРАНИЦЕ ПРОДУКТОВ *}
{elseif strpos($smarty.server.REQUEST_URI,"/show-products/") !== false}

   контент  

{/if}

Specify what should be in the address, for example "/show-product/" or "/base/"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question