是否可以使用没有tpl文件的smarty模板?

I need to assign data to javascript source. Is it possible to use smarty template without tpl file. Like this...

$sHtml = '
    {foreach from=$myArray key=k item=v}
       <li>{$k}: {$v}</li>
    {/foreach}
';

$arr = array(9 => 'Tennis', 3 => 'Swimming', 8 => 'Coding');
$oSmarty = new smarty();
$oSmarty->assign('myArray', $arr);
$result = $oSmarty->fetch($sHtml);

echo $result;

Return like this...

<li>9: Tennis</li>
<li>3: Swimming</li>
<li>8: Coding</li>

From Smarty 3 on you can do that with

$smarty->fetch('string:'.$content);

See here fore more information: String Template Resources

If you are using Smarty < 3 you could save the content of $sHtml in a temporary file and pass the file name to the fetch call:

$smarty->fetch('file:/full/path/to/tmp/file');