Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

setting selected attribute for an <option>


Go to End


3 Posts   1452 Views

Avatar
jcoby

Community Member, 2 Posts

7 October 2008 at 9:55am

I'm trying to build a <select> manually with all of the children of a certain page. The code looks like:

<% control ChildrenOf(case-studies) %>
<% if ClassName = RedirectorPage %>
<option value="$ContentSource.Link">$Title</option>
<% end_if %>
<% end_control %>

How can I set the selected attribute if the current page is a child of the page being use for the <option>?

Avatar
(deleted)

Community Member, 473 Posts

7 October 2008 at 10:37am

Edited: 07/10/2008 10:37am

<% control ChildrenOf(case-studies) %> 
          <% if ClassName = RedirectorPage %> 
<option value="$ContentSource.Link"<% if LinkOrSection = section %> selected="selected"<% end_if %>>$Title</option> 
<% end_if %> 
<% end_control %>

Should do it.

Avatar
jcoby

Community Member, 2 Posts

8 October 2008 at 4:20am

worked perfectly! thank you!