PHP foreach to Smarty -


i trying rewrite rss feed parser php code smarty. smarty not work me somehow. can me out please?

<ul> <?php foreach ($feed['items'] $item): ?>     <li>         <a href="<?= $item['link']; ?>"><?= $item['title']; ?></a>     </li> <?php endforeach; ?> </ul> 

my smarty code updated: 12/07/13

{foreach name=aussen item=$feed.items from=$item}     <li>         <a href="{$item.link}">{$item.title}</a>     </li> {/foreach}  

there lot of issues smarty code. first, , foremost, should not have php logic , smarty formatting in same file. should assign smarty variables separately , call smarty formatting. if stick existing stuff, you'll need take account following:

  1. syntax of foreach wrong - correct syntax {foreach from=$variable item=$loop_var}

  2. php variables not automatically available in smarty - you'll need add smarty {assign} directive combination of{php}echo $php_var{/php}` php variable smarty.

  3. syntax {php}$item['title']{/php} invalid syntax php , result in syntax error.

on whole, approach flawed. smarty presentation (view) layer in mvc app - , you're trying combine 1 file. don't. if not sure how set application mvc, smarty not you.


Comments