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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

problem with if blocks in templates


Go to End


10 Posts   2245 Views

Avatar
bummzack

Community Member, 904 Posts

12 November 2009 at 7:21am

What about a simple hack? Something along these lines:

function getFaculty($facultyType) {
	$type = str_replace('_', ' ', $facultyType);
	return DataObject::get( 'FacultyPage', "`FacultyType` = '$type'" );
} 

That code simply replaces all underscores with spaces. Therefore underscore is an alias for space.
In the template you would then write:

<% control Faculty(Associate_Professor) %>
      <p><a href="$Link">$Title</a></p>
<% end_control %> 

Note that I put an underscore instead of a space there. And that I wrote Faculty instead of getFaculty, since you usually skip the "get" in the Template and it still maps to to correct function.

Avatar
ttyl

Community Member, 114 Posts

12 November 2009 at 7:46am

that does the trick, thanks!

Go to Top