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.

Template Questions /

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

Multiple ||


Go to End


14 Posts   2720 Views

Avatar
mschiefmaker

Community Member, 187 Posts

24 October 2009 at 9:37pm

On a template I want to display some text if anyone of four conditions are meet ie

<% if Referrals || Supervision || Consultation || Review %>

but I can do this as I can only have 2 conditions. I can't see a way t o nest the conditions so how do I test for this?

Know this has got to be an easy answer but I am stumped.

Thanks

Catherine

Avatar
Willr

Forum Moderator, 5523 Posts

25 October 2009 at 1:16am

No the template language does not support that. In order to get that to work you could write a small PHP function which does the or comparison. Like

// in say page.php but could be your own page type
function IfSomething() {
return ($this->Referrals || $this->Supervision || $this->Consultation || $this->Review) ? true : false;
}

<% if IfSomething %>....

Avatar
mschiefmaker

Community Member, 187 Posts

25 October 2009 at 11:22am

Hi Will

Thanks for this, realised I shouldn't have been looking for that kind of function in a tempalte this morning

Cheers

Catherine

Avatar
mschiefmaker

Community Member, 187 Posts

25 October 2009 at 12:37pm

Ok so I am stumped. I have added to DirectoryPage.php in the DirectoryPage_Controller section

class DirectoryPage_Controller extends Page_Controller {

...

function Offerings() {
return True;
}

}
(I have removed the actual decision logic for now as I just can't get the function to apply)

and to DirectoryPage.ss I have added

<% if Offerings %>
<li>Avaliable <% end_if %> ...

but Avaliable does not display. I know its got to be simple but what am I doing wrong?

Thanks

Catherine

Avatar
Willr

Forum Moderator, 5523 Posts

25 October 2009 at 12:45pm

Try moving it to the DirectoryPage class rather then the controller, Or move that function to the page controller in Page.php and see if it picks the function up in either of those 2 places (you might want to put a die(); statement in the function so you can obviously tell when the function is called.

Avatar
mschiefmaker

Community Member, 187 Posts

25 October 2009 at 1:59pm

Tried both page.php and the DirectoryPage section of DirectoryPage.php neither worked. If I put die(); inside another function on DirectoryPage it works but not for Offerings.

For some reason it is this function no applying. Have tried to using flush and saving the page again in the CMS but to no avail. Any other suggestions?

Thanks

Catherine

Avatar
Willr

Forum Moderator, 5523 Posts

25 October 2009 at 2:05pm

Strange. Perhaps try changing the function name to getOfferings() and leaving the template if as <% if Offering %>.

You aren't inside a control or any other loop on the DirectoryPage.ss are you?

Avatar
mschiefmaker

Community Member, 187 Posts

25 October 2009 at 2:11pm

Yes I am inside a control. ?

Go to Top