[PHPTAL] really don't get it. php: exprssion?true:false

Mynthon mynthon1 at gmail.com
Wed May 16 15:39:05 CEST 2007


i try to do select with selected option. I have something like this:

class options {
    public $value;
    public $content;
    public $selected;

    function options($value, $content, $selected=false) {
        $this->value = $value;
        $this->content = $content;
        $this->selected = $selected;
    }
}

$option = array();
$option[]=new options('a', 10);
$option[]=new options('b', 20);
$option[]=new options('c', 30);
$option[]=new options('d', 40);
$option[]=new options('e', 50);
$option[]=new options('f', 60, true);
$option[]=new options('g', 70);

$template->options = $option;

in template i have:

<select name="s">
<option tal:repeat="opt options"
tal:attributes="value opt/value;
selected php: repeat.opt.selected ? 'selected' : false"
tal:content="opt/content" />
</select>

and line:
selected php: repeat.opt.selected ? 'selected' : false"
doesnt work properly.

when i have
selected php: repeat.opt.selected ? 'selected' : false"
none option is selected (no attribute selected="selected")

but when i change it to
selected php: repeat.opt.selected ? 'selected' : 'foo'"
all elements have selected="selected" attribute.

dont get it.

when repeat.opt.selected it should show selected='"selected" or
selected="foo" otherwise. am i wrong?

second question:
is there any reference to current node? smth like this:
<div tal:content="php: nl2br(this.nodeValue)" />
?


-- 
mynthon
http://www.mynthon.net



More information about the PHPTAL mailing list