Jump to:

23360 Posts in 18100 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » problem with if blocks in templates

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

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

Page: 1 2
Go to End
Author Topic: 1116 Views
  • banal
    Avatar
    Community Member
    901 Posts

    Re: problem with if blocks in templates Link to this post

    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.

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: problem with if blocks in templates Link to this post

    that does the trick, thanks!

    1116 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.