1260 Posts in 349 Topics by 485 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 842 Views |
-
Page control check for content

15 November 2010 at 11:31pm
I've scan the forums and read this page http://doc.silverstripe.org/built-in-page-controls 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?
-
Re: Page control check for content

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!
-
Re: Page control check for content

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" -
Re: Page control check for content

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; -
Re: Page control check for content

16 November 2010 at 12:52am
Thanks, that's worked. Making progress!!
-
Re: Page control check for content

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...
| 842 Views | ||
|
Page:
1
|
Go to Top |


