Or simply use a combination of strip_tags and trim?
trim( strip_tags( $this->SidebarContent ) );
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Or simply use a combination of strip_tags and trim?
trim( strip_tags( $this->SidebarContent ) );
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.
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
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.
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
Look into the silverstripe Debug module. Something like
Debug::show(Menu(2));
Should show everything you need.
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!
Sam
Edit: 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.