[eluser]Unknown[/eluser]
How to add form elements (example: form_input) in twig template view?
My controller:
class Twig_sample extends CI_Controller {
public function index() {
$params = array(
'name' => 'Tony',
'friends' => array(
array('firstname' => 'John', 'lastname' => 'Smith'),
array('firstname' => 'Britney', 'lastname' => 'Spears'),
array('firstname' => 'Brad', 'lastname' => 'Pitt'),
)
);
$this->load->helper('form');
$this->load->library('twig');
$this->twig->add_function('base_url');
$this->twig->display('hello.php', $params);
}
}
My views file:
Layout.php
<html>
<head>
<title>{% block title %}My page{% endblock %}</title>
</head>
<body>
<div id="left-box">{% block leftbox %}This is the left box.{% endblock %}</div>
<div id="content">{% block content %}{% endblock %}</div>
</body>
</html>
index.php
{% extends "layout.php" %}
{% block title%}
{{ parent() }} - About me : {{ name }}
{% endblock %}
{% block leftbox %}My name is {{ name }}{% endblock %}
{% block content %}
My friends are:-
<ul>
{% for person in friends %}
<li>{{ person.firstname}} {{ person.lastname }}</li>
{% endfor %}
</ul>
{{ base_url() }}
form_open('email/send');
form_input('username', 'johndoe');
form_close();
{% endblock %}