Jump to:

1384 Posts in 493 Topics by 522 members

Themes

SilverStripe Forums » Themes » Page control check for content

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1041 Views
  • Corry
    Avatar
    Community Member
    17 Posts

    Page control check for content Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Page control check for content Link to this post

    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!

  • Corry
    Avatar
    Community Member
    17 Posts

    Re: Page control check for content Link to this post

    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"

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Page control check for content Link to this post

    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;

  • Corry
    Avatar
    Community Member
    17 Posts

    Re: Page control check for content Link to this post

    Thanks, that's worked. Making progress!!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Page control check for content Link to this post

    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...

    1041 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.