|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
DEA7H Smarty Rookie
Joined: 22 Nov 2012 Posts: 10
|
Posted: Thu Nov 22, 2012 8:52 pm Post subject: Peredacha peremennoi v shablon |
|
|
Здравствуйте!
Как просто передать переменную в нужный мне файлик .tpl?
Я делаю вот так:
Code: | $content = $template->fetch("news.tpl");
$template->assign('content',$content);
$template->assign('row',$row);
$template->display($_SERVER['DOCUMENT_ROOT']."/templates/default/main.tpl");
|
Тоесть, я передаю переменную row в файлик main.tpl. Передается переменная когда срабатывает вот эта строчка.
А мне нужно тут же передать эту переменную в файл news.tpl, тоесть передать ее и main.tpl и в news.tpl. Она мне нужна в news.tpl поскольку я юзаю:
Code: | $content = $template->fetch("news.tpl");
$template->assign('content',$content); |
Как такое сделать?
Заранее благодарен. |
|
Back to top |
|
DEA7H Smarty Rookie
Joined: 22 Nov 2012 Posts: 10
|
Posted: Thu Nov 22, 2012 10:39 pm Post subject: |
|
|
Сказали сделать вот так:
Code: | $template->assign('row',$row);
$content = $template->fetch("news.tpl");
$template->assign('content',$content);
$template->display($_SERVER['DOCUMENT_ROOT']."/templates/default/main.tpl"); |
Тоесть assign('row',$row) поместить перед $template->fetch("news.tpl");. Это действительно работает. Но только не в моем случае!
Вот код самого NEWS.TPL:
Code: | {foreach $row as $items}
<div class="centerblock">
<div class="headertxt">{$items.id}</div>
<div class="contentinfo">{$items.name}</div>
{$items.story}
</div>
{/foreach} |
Подскажите возможно чтото не так в цикле или проблемы с использованием ассоциативного масиива.
Заранее благодарен. |
|
Back to top |
|
DEA7H Smarty Rookie
Joined: 22 Nov 2012 Posts: 10
|
Posted: Thu Nov 22, 2012 11:04 pm Post subject: |
|
|
Проблема решена! |
|
Back to top |
|
|
|
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
|