Because "selected" is one of those special attributes in php you can also just use:
<option tal:repeat="item items" tal:attributes="selected item/active" /> If I'm not mistaken, a boolean value for "active" should work the way you want it. On 4/28/09, Julian Haupt <julian.ha...@hauptmedia.de> wrote: > Hi, > >> The way you USA should work, but try this: >> >> <tal:block tal:repeat="c categories"> >> <option tal:attributes="value c/id;selected php: f.categoryid == >> c.id" tal:content="c/category"></option> >> </tal:block> > > In general it might be a bad idea to use php code and explicit > comparisons in the templates. This is a bad practice which entangles the > view with the underlying business logic. > > I've added a new TALES-Keyword for this purpose: condition > > It works like mysql's IF statement. If the expression in the first block > is true, execute the next block, otherwise the last block. > > function phptal_tales_condition($expression, $nothrow) { > // split OR expressions > $exps = preg_split('/\s*\|\s*/sm', $expression); > > if (!isset($exps[1])) { > $exps[1] = 'nothing'; > } > > if (!isset($exps[2])) { > $exps[2] = 'nothing'; > } > > return '(' . phptal_tales($exps[0], $nothrow) . ') ? ' . > phptal_tales($exps[1], $nothrow) . ' : '. phptal_tales($exps[2], > $nothrow); > } > > > It might not be perfect, because it uses TALES' "|" operator for a > completely different operation. > > Please note: as you cannot do explicit comparisons with this keyword, > you must define the result of the comparison in your model. > > With the help of the condition keyword you can write the above template > like this: > > <tal:block tal:repeat="c categories"> > <option tal:attributes="value c/id; selected condition: c.active| > string:selected|not:true" tal:content="c/category"></option> > </tal:block> > > The "active" property might be determined like this: > > $id = (int)$_REQUEST["id"]; // get the id in the url query > > $formSQL = "SELECT i.id, categoryid, category, title, publication, > DATE_FORMAT(date, '%Y/%m/%d') AS fDate, author, summary, filename, > IF(i.id=$id,1,NULL) AS active FROM `resources-items` AS i LEFT JOIN > `resources-categories` AS c ON i.categoryid=c.id WHERE i.id=$id"; // get > the row to be edited > > $t = new PHPTAL("test.html"); > $t->categories = getRows("SELECT id, category FROM > `resources-categories` ORDER BY category"); // get all categories > $t->form = getRows($formSQL); > > > Greetings, > > Julian Haupt > > > > -- > Julian Haupt B.Sc. > > Hauptmedia > Landgraf-Georg-Str. 25 > 64283 Darmstadt > > fon: +49 6151 - 278 041 7 > fax: +49 6151 - 278 041 8 > mobil: +49 179 - 901 548 7 > email: julian.ha...@hauptmedia.de > web: www.hauptmedia.de > > St.-Nr. 007/825/32605 > > > _______________________________________________ > PHPTAL mailing list > PHPTAL@lists.motion-twin.com > http://lists.motion-twin.com/mailman/listinfo/phptal > -- -- Tjerk _______________________________________________ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal