I use CodeIgniter 1.7.2
blog file at system/application/conrollers/blog.php
function index()
{
$this->load->library('smarty_parser');
$this->load->helper('html');
$data['title'] = 'Your title';
$data['todo_list'] = array('Clean House', 'Call Mom', 'Run Errands');
$this->smarty_parser->parse("ci:content_template.tpl", $data);
}
content_template.tpl at system/application/views/content_template.tpl
{foreach from=$todo_list item=$items}
<li>{$items}</li>
{/foreach}
I run localhost/codeigniter_172/blog/
show error following:
A PHP Error was encountered Severity: User Error
Message: Smarty error: [in ci:content_template.tpl line 22]: syntax error: 'foreach: 'item' must be a variable name (literal string) (Smarty_Compiler.class.php, line 1174)
Filename: smarty/Smarty.class.php
Line Number: 1095
Parse error: syntax error, unexpected T_ENDFOREACH in C:\xampp\htdocs\codeigniter_172\system\cache\%C^43F^43FD50D8%%ci:content_template.tpl.php on line 29
when I add literal at system/application/views/content_template.tpl
{literal}
{foreach from=$todo_list item=$items}
<li>{$items}</li>
{/foreach}
{/literal}
I run localhost/codeigniter_172/blog/
show the following:
My Todo List
{foreach from=$todo_list item=$items}
{$items} {/foreach}
Copyright @ 2010 CodeIgniter 1.7.2
Could you solve problem, foreach array $todo_list with CI & Smarty ?