Jump to:

23370 Posts in 18145 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » using built in page controls in "Content" area?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2 3
Go to End
Author Topic: 3241 Views
  • janulka
    Avatar
    Community Member
    80 Posts

    using built in page controls in "Content" area? Link to this post

    Hello,
    Is it possible to somehow use built in page controls in Content area?
    I would like to use e.g. $Now.Year or $Title or $CurrentMember.FirstName inside the Content without having to make templates for this..
    Thanks

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: using built in page controls in "Content" area? Link to this post

    Do you mean inside of the $Content output itself?

  • janulka
    Avatar
    Community Member
    80 Posts
  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: using built in page controls in "Content" area? Link to this post

    how about...
    put something like $MyContent instead of $Content in your Pages.ss
    create a function like...

    function MyContent() {
       $vd = new ViewableData();
       $t = SSViewer::fromString('<% control CurrentPage %>'.$this->Content.'<% end_control %>');
       $ad = new ArrayData(array('CurrentPage' => $this));
       return $vd->customise($ad)->renderWith($t);
    }

    ...it's just a guess, p[robably overcomplicated, but I think it'll work

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: using built in page controls in "Content" area? Link to this post

    UserForms requires the $UserDefinedForm variable in the Content area of the form page, so that seems to be an example of it working somehow. If I were you, I'd start by looking under the hood of the UserForms module.

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: using built in page controls in "Content" area? Link to this post

    I'd disagree Ryan - I've looked at that before and it does a straight str_ireplace for the "$UserDefinedForm" with the userform - not very helpful to access the full power of the standard page controls for merging things like $Now

  • theoldlr
    Avatar
    Community Member
    103 Posts

    Re: using built in page controls in "Content" area? Link to this post

    swaiba, can you help me understand your example a little better? I'd like to use this idea for something a little different. Let's say, for example, I have a sub template file already made to display what I want. which would make your example more like this:

    function MyContent() {
    $vd = new ViewableData();
    $t = SSViewer::getTemplateFile('mysite/include/SubTemplate.ss');
    $ad = new ArrayData(array('CurrentPage' => $this));
    return $vd->customise($ad)->renderWith($t);
    }

    What would you put into the WYSIWYG to make it render this? "$MyContent"? Wouldnt that just display "$MyContent" with the rest of what is in your HTMLEditorField rather than call the function?

    Thanks!

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: using built in page controls in "Content" area? Link to this post

    sure...

    you see I think you could get away with...
    the function would go in your Page_Controller...

    function MyContent() {
       $t = SSViewer::fromString($this->Content);
       return $this->customise()->renderWith($t);
    }

    and the $MyContent would go into templates/Pages.ss replacing $Content - this mean where the template would get the "Content" and put it ont he page it calls the MyContent function and this in turn takes the "Content" and treats it as a template. because we are in "Page" context it should merge.

    My previous example did a little more to create it's own merging/rendering process, wrap the "Content" in a control and then pass the page data in... I did this becasue it seemed wrong to render within itself...

    function MyContent() {
    $vd = new ViewableData();
    $t = SSViewer::fromString('<% control CurrentPage %>'.$this->Content.'<% end_control %>');
    $ad = new ArrayData(array('CurrentPage' => $this));
    return $vd->customise($ad)->renderWith($t);
    }

    3241 Views
Page: 1 2 3
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.