0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Very much appreciated. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.