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.

Themes /

Discuss SilverStripe Themes.

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

Page control check for content


Reply


6 Posts   1108 Views

Avatar
Corry

Community Member, 17 Posts

15 November 2010 at 11:31pm

I've scan the forums and read this page [url]http://doc.silverstripe.org/built-in-page-controls[/url] about 20 times ... but can't find an answer to my question.

In the template, how could I include a test for whether the current page in the control data feed has $Content from the CMS?

I've tried if <% if Content %> but it doesn't ever evaluate to true.

Have also tried a function in the page class like

function checkContent() {
return ($this->Content);
}


and <% if checkContent %> in the template but no luck.

Does anyone know a way I could test for this?

Avatar
swaiba

Forum Moderator, 1805 Posts

15 November 2010 at 11:59pm

are you looking for content with text on it?

how about?

function checkContent() {
return (!empty(trim(strip_tags($this->Content))));
}

and be sure to check your function is being called with a Debug::show()! and then you can debug the results of the function too!

Avatar
Corry

Community Member, 17 Posts

16 November 2010 at 12:34am

Thanks for the quick response.

Unfortunately that code doesn't get past the dev/build stage:
"Fatal error: Can't use function return value in write context in /public_html/dev/mysite/code/Resource.php on line 46"

Avatar
swaiba

Forum Moderator, 1805 Posts

16 November 2010 at 12:36am

yeah - I've seen that error before - it will be fine if you split the lines up...

$s = strip_tags($this->Content);
$s = trim($s);
$b = !empty($s);
return $b;

Avatar
Corry

Community Member, 17 Posts

16 November 2010 at 12:52am

Thanks, that's worked. Making progress!! :-)

Avatar
swaiba

Forum Moderator, 1805 Posts

16 November 2010 at 12:56am

nice, I just went to check the error and it is the php empty function - according to the docs it ONLY takes a variable and cannot take a return value from a function. I wonder why it can identify a value as empty/not empty but is unable to take a return value and do the same...