Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Need help on Smarty.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian
View previous topic :: View next topic  
Author Message
SmartyUser18
Smarty n00b


Joined: 01 Aug 2018
Posts: 1

PostPosted: Wed Aug 01, 2018 5:28 pm    Post subject: Need help on Smarty. Reply with quote

Hello everybody! I'm not familiar with Smarty at all. There is a question.
The main page displays the content using the variable ($content), first the main categories are displayed, if one of them is selected, subcategories appear below, and then the list of products is displayed. (Online store). How to make it so that when selecting a category, only the subcategories remain, and the categories are hidden? More precisely, how to hide {function}, if the display is different. The variable $content displays the following content:

Code:
     {* Рекурсивная функция вывода дерева категорий *}
        {function name=categories_tree}
        {if $categories}
      
<section>

        {foreach $categories as $c}
                {* Показываем только видимые категории *}
                {if $c->visible}
                        {if $c->id >= 6 && $c->name!='index'}
                        <a href="catalog/{$c->url}#shop" data-category="{$c->id}">
                            <div class="plan">
                            <div class="title ">{$c->name|escape}</div>
                          <div class="price"><i class="fa fa-map-marked" aria-hidden="true"></i></div>
                          <div class="lines">
                              <div class="line" style="width: 69px;"></div>
                              <div class="line" style="width: 59px;"></div>
                              <div class="line" style="width: 66px;"></div>
                              <div class="line" style="width: 46px;"></div>
                          </div>
                        </a>
                            </div>
                        {/if}
                {/if}
        {/foreach}

        {/if}
        {/function}
        {categories_tree categories=$categories}
       

   
</section>

<section>
                        {* Рекурсивная функция вывода дерева категорий *}
                       
                        {function name=categories_tree3}
                        {if $categories}

                        {foreach $categories as $c}
                            {* Показываем только видимые категории *}
                        {if $c->visible}
                            <a href="catalog/{$c->url}#shop3" data-category="{$c->id}">
                            <div class="plan">
                            <div class="title ">{$c->name|escape}</div>
                          <div class="price"><i class="fa fa-map-marked" aria-hidden="true"></i></div>
                               <div class="lines">
                              <div class="line" style="width: 69px;"></div>
                              <div class="line" style="width: 59px;"></div>
                              <div class="line" style="width: 66px;"></div>
                              <div class="line" style="width: 46px;"></div>
                          </div>
                            </a>
                     </div>
                                {/if}
                        {/foreach}

                        {/if}
                        {/function}
                       
                       
                        {assign var="menu_ex" value=true}
                       
                        {function name=categories_tree2}
                        {if $categories}

                        {foreach $categories as $c}
                                {* Показываем только видимые категории *}
                                {if $c->visible}
                                    {if $category->id == $c->id}
                                            {assign var="menu_ex" value=false}
                                            {categories_tree3 categories=$c->subcategories}
                                    {/if}
                                {/if}
                        {/foreach}

                        {/if}
                        {/function}
                       
                        {function name=categories_tree4}
                        {if $categories}

                        {foreach $categories as $c}
                                {* Показываем только видимые категории *}
                                {if $c->visible}
                                    {if $category->parent_id == $c->id}
                                            {assign var="menu_ex" value=false}
                                            {categories_tree3 categories=$c->subcategories}
                                    {/if}
                                {/if}
                        {/foreach}

                        {/if}
                        {/function}
                       
                        {categories_tree2 categories=$categories}
                       
                        {if $menu_ex}
                            {categories_tree4 categories=$categories}
                        {/if}
                       
</section>

{$content}

<section>   
            <!--Каталог товаров-->
            {function name=products}
            {if $products}


            {*include file='pagination.tpl'*}

                        {foreach $products as $product}

                            {foreach $product->variants as $v} 
                      <a href="/buy/?p={$product->name|escape}&s={$v->price|convert}#shop4">
                            <div class="plan" style="background-image: url({$product->image->filename|resize:155:200}); background-repeat: no-repeat; background-position: bottom;">
                            <div class="title ">{$product->name|escape}</div>
                          <div class="price">{$v->price|convert} ₴ </div>
                              <div class="lines">
                              <div class="line" style="width: 69px;"></div>
                              <div class="line" style="width: 59px;"></div>
                              <div class="line" style="width: 66px;"></div>
                              <div class="line" style="width: 46px;"></div>   
                              </div>
                     <div class="bottom-buy"><i class="fa fa-shopping-basket" aria-hidden="true"></i></div>
                     </div>
                     {/foreach}
                            </a>
                               
                        {/foreach}


            {*include file='pagination.tpl'*}   
            <!-- Список товаров (The End)-->

            {else}

            {/if}
            {/function}
           
</section>


I'm writing through an interpreter, I hope the question is clear. Thank you very much in advance. Smile
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Aug 02, 2018 1:41 pm    Post subject: Reply with quote

Для этого надо переписать функцию вывода дерева.
Вряд ли это будет большим сюрпризом?

P.S.
Почему не написать нормальный плагин-итератор вместо того, чтобы городить функцию в шаблоне?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP