2

I am trying to use SmartyViewRendere in Yii. I got everything setup according to the instructions for using Smarty with Yii.

In my application I want to render a template called widgets_sidebar_template.tpl

<h1>Widgets bewerken voor Sidebar #<?php echo $model->id; ?></h1>
<?php $this->render('widgets_sidebar_template', array(
        'available_widgets'=>$available_widgets
    )
) ?>

This works fine.

Then the widgets_sidebar_template.tpl file:

$smarty->assign('availables', $available_widgets);
?>
<article id="widgets_container">
    <ul id="available_widgets" class="connect">
    <span>Beschikbaar</span><br><br>
    {foreach from=$availables key=k item=available}
        <li>{$available}</li>
    {/foreach}
    </ul>

    <ul id="active_widgets" class="connect">
        <span>Actief</span><br><br>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</article>

This file gives the error

Undefined index: availables 

So the first thing that came up to me is that I needed to make sure $available_widgets is an array. So I figured that out and I am 100% sure it's an array with data. Then I checked if the $available_widgets is actually assigned to 'availables' ($availables), so i removed the:

$smarty->assign..

This gave me the same error as it was, so my guess is that i'm doing something wrong with the assigning of the 'availables' smarty array.

I hope one of you guys can give me some more advice based on this intel. Thanks:)

Sjaak Rusma
  • 1,424
  • 3
  • 23
  • 36

1 Answers1

1

You can not use $smarty->assign in a smarty template. Also PHP tags will not work inside Smarty templates. I guess you are talking about this SmartyRenderer: https://github.com/yiiext/smarty-renderer

The latest version requires Smarty version 3 or higher, it might not work with Smarty 2.

For your template you can use the following syntax to assign a variable value in Smarty:

{$availables=$available_widgets}

In your example you might even just use $available_widgets in the foreach loop.

cebe
  • 3,610
  • 1
  • 23
  • 37