Reputation: 17818
HTML CODE:
<html><body> {section name=a loop=$items} {$items[a].title} {include file="/directory/showstuff.html" video=$items[a]} {/section} </body> </html>
PHP CODE:
$pid = '12';
$items = $cbvid->get_channel_items($pid);
assign('items',$items);
This is perfectly working fine, with the integer 12 being my php code. However, I wanted to add the integer 12 and call it from the html code, but it didn't work.
I tried:
<html><body> {section name=a loop=$cbvid->get_channel_items(12)} {$items[a].title} {include file="/directory/showstuff.html" video=$items[a]} {/section} </body> </html>
But it didn't work. How can I do it?
Upvotes: 0
Views: 106
Reputation: 3682
Just don't do it. That looks like if you would like to move business logic to representation layer - that is not what Smarty is used for. Prepare data beforehand, then give it to template.
But if you really want it to work, use foreach
<html><body>
{foreach from=$cbvid->get_channel_items(12) item=video}
{$video.title}
{include file="/directory/showstuff.html" video=$video}
{/foreach}
</body> </html>
The reason why it did not work with sections, was because you have no $items
variable defined, still, you are trying to get value of it. This is where you need to use assign
.
<html><body>
{assign var="items" value=$cbvid->get_channel_items(12)}
{section name=a loop=$items}
{$items[a].title}
{include file="/directory/showstuff.html" video=$items[a]}
{/section}
</body> </html>
Still, I prefer foreach
.
Upvotes: 2