i am first time user of PHPTAL and i am not able to provide value to input box using PHPTAL i have three files 1.index.php
require_once 'includes/lib/PHPTAL-1.2.2/PHPTAL.php';
// create a new template object
$template = new PHPTAL('components/epayroll/new/employeeView.xhtml');
require_once("employeeClass.php");
$people = array();
$people[] = new Person("foo");
// put some data into the template context
$template->title = 'The title value';
$template->people = $people;
// execute the template
try {
echo $template->execute();
}
catch (Exception $e){
echo $e;
}
2.empView.Xhtml
<td> <tal:block metal:define-macro="text"> <input name="${name}"
tal:attributes="id id | nothing" type="text" value="person/name"
/> </tal:block> </td>
3.empClass.php
class Person {
public $name;
function Person($name){
$this->name = $name;
}
}
please help me with steps how to do this.
thanks for your precious response
In employeeView.xhtml
you need to iterate over people:
<div tal:repeat="person people">
<!-- you can use person here -->
</div>
If you wanted to call the macro, then:
<div tal:repeat="person people">
<div metal:use-macro="text" />
</div>
You might also add something like tal:define="id repeat/person/key"
to the inner <div>
if you want array keys to be used as IDs.
And to set value of <input>
use:
<input value="${person/name}">
which is a short-hand for:
<input tal:attributes="value person/name">