PHPTAL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

PHPTAL

Post by shiznatix »

So yes I am using PHPTAL for templating and it is working out quite well for me.

The problem I have is trying to have a select option pre selected when populating the options dynamically. Like this:

Code: Select all

<select name="fkStateId">
    <option value=""></option>
    <option tal:repeat="state States" tal:attributes="value state/Id" tal:content="state/State">
    </option>
</select>
How would I go about making a conditional attribute? I have tried things like this:

Code: Select all

<select name="fkStateId">
    <option value=""></option>
    <option tal:repeat="state States" tal:attributes="value state/Id; selected php: state/Id == SelectedState ? 'selected' : ''" tal:content="state/State">
    </option>
</select>
but that gives me the error that state/Id does not exist or whatever. I searched google and the mailing list stuff to no real solution. Anyone know how this could be accomplished?
Post Reply