Jump to content
  • 0

Smarty vc {section}


klierik
 Share

Question

Приветствую.

Кто имел опыт работы со смарти, подскажите пожалуйста как передавать значение одной переменной из внешнего цыкла во внутрений?

пример:

{section name=i loop=$categories_tree}

{if $categories_tree[i].categoryID != 1}

{* main level menu *}
{if $categories_tree[i].level == 1}

... foo ...

{* sub level menu *}
{else}
<ul>
{section name=j start=i loop=$categories_tree}

... foo ...

{/section}
</ul>
{/if}


{/if}
{/section}

В данном случае интересует как передать значение "i" для start (внутренний цикл),

или же как присвоить значение "i" для "j"?

Спасибо.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

пробывал такое... не срабатывает ((

... foo ...
{section name=j start=$i loop=$categories_tree}
<div>{$i}</div>
{/section}

более того $i не выводится.... пустые дивы.. $j так же само :D

так же хочу спросить на перед, можно ли как то значение $j потом присвоить для $i?

Link to comment
Share on other sites

  • 0

скажи, плз, как его от туда вывести?

имеем: таблица со списком элементов меню (2х уровневое)

каждый пункт имеет ID родителя.

хочу вывести ето все в стиле:

<ul>
<li></li>
<li></li>
<li></li>
<li>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</li>
</ul>

вывести первый уровень легко. а вот как начать выводить второй пока не получается (

Link to comment
Share on other sites

  • 0
скажи, плз, как его от туда вывести?

вывести первый уровень легко. а вот как начать выводить второй пока не получается (

:D

Я бы для начала преобразовал массив из плоского вида в дерево. Так будет проще и понятнее.

$arr = array(
1 => array ( 'title' => 'Element 1', 'id' => 1, 'children' => array (
3 => array ( 'title' => 'Element 1.1', 'id' => 3 ),
4 => array ( 'title' => 'Element 1.1', 'id' => 4 ),
) ),
2 => array ( 'title' => 'Element 2', 'id' => 2 )
);

Делаем файл с названием, например menu.tpl

<ul>
{foreach from=$arr item="element"}
{$element.title}
{if $element.children}{include file="menu.tpl" arr=$element.children}{/if}
{/foreach}
</ul>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy