2

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

1 Answers1

1

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">
Kornel
  • 97,764
  • 37
  • 219
  • 309
  • Thanks @porneL so far i tried Name: this worked but still not able to insert value in textbox. i am new in templating.please guide me in steps so that i can follow it. beside that i am not using
    :--- thanks once again
    – Sajad A Wani Jan 26 '14 at 08:47
  • @SajadA oh, I didn't notice that `` was the problem, I've expanded my answer – Kornel Jan 27 '14 at 17:10