3217 Posts in 853 Topics by 812 members
| Go to End | ||
| Author | Topic: | 1727 Views |
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

24 August 2009 at 6:15pm
Or simply use a combination of strip_tags and trim?
trim( strip_tags( $this->SidebarContent ) );
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

24 August 2009 at 11:33pm
I've read bad things about strip_tags not working properly, i would use the inbuilt SS function (havent investigated how it works) and removing white space. In conjunction with the RAW version of the content.
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

25 August 2009 at 12:40pm
Hi all,
Any thoughts on how to get the Menu(2) part of the Sidebar function working, which is really the only remaining issue (see my previous post)?
It is always passing true even when there is no Menu(2) items.Sam
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

25 August 2009 at 11:39pm
Debug what Menu(2) actually returns. There may be a count number or a total number of items stored with in the object and you can check to see if that is 0.
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

26 August 2009 at 4:46am
My knowledge of php is fairly poor, so I am not sure how I would determine what Menu(2) returns.
What and where would be the code that I would use?Thanks,
Sam -
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

26 August 2009 at 7:13am
Look into the silverstripe Debug module. Something like
Debug::show(Menu(2));
Should show everything you need.
-
Re: Conditional Sidebar <% if Menu(2) || Photo || SidebarContent %> doesn't work

5 September 2009 at 11:40am Last edited: 9 December 2009 9:18am
I am happy to report that from the suggestions above and from the IRC channel, I was able to complete the code I was looking for.
Its... function Sidebar() { return ($this->Photo()->exists() || strip_tags($this->SidebarContent) || $this->Menu(2)->Count() > 0);}
The ternary operators ? true : false; at the end are not necessary. it's either true or false already, no need for an extra check.
The strip_tags seems to work fine for checking for raw text. It doesn't return true if there are only spaces in the htmltext field. I couldn't get Will's suggestion $this->obj('SidebarContent')->RAW() to work.
The Debug::show(Menu(2)); didn't show me default output to use in function -- at least I couldn't figure it out from what was shown.Thanx all again for the help!
SamEdit: See http://www.silverstripe.org/template-questions/show/273271#post273271 for conditional if statements regarding images. I updated
the above by changing $this->Photo to $this->Photo()->exists as just $this->Photo was returning as a false true.
| 1727 Views | ||
| Go to Top |



