Jump to:

23460 Posts in 18907 Topics by 2877 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: 3306 Views
  • theoldlr
    Avatar
    Community Member
    103 Posts

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

    OK, I think I understand what you are saying... basically this would allow you to use a CMSfield to fill in the info between <% control whatever %> and <% end control %>. What I would really like to know is how to do something like this within the actual $Content CMSField. In my case I am not thinking so much in terms of built in page controls, but maybe displaying data from a DataObjectManager. This would give more control to the end user for positioning their data nicely within the normal content. I looked into the idea a little more, and I thought that short codes might be the way to achieve this, but I'm not sure how <% control %> would render doing it this way. Any idea?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

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

    wellllll.....

    the issue is getting access to the data in the template code place in the Content. As long as you had something like...

    in content... (remember param1 & param2 must be plain text, they cannot be variables)

    <% control GetMyData(param1,param2) %>
    $SomeData
    <% end_control %>

    in Page_controller ...

    function GetMyData(param1,param2) {
    return DataObject::get(param1,param2);
    }

    ...in might just work

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

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

    Just to confirm, the following does exactly as I guessed...I'm now using it

    Page.php

    ...
    class Page_Controller extends ContentController {
    ...
       public function TemplateContent() {
          return $this->renderWith(SSViewer::fromString($this->Content));
       }
    ...
    }
    ...

    templates\Layout\Page.ss

    replace...

    $Content

    with...

    $TemplateContent

  • joelg
    Avatar
    Community Member
    129 Posts

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

    Hi

    Maybe all of this could be done with a ShortCodeParser... Much easier I think.

    Joel

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

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

    Hi Joel,

    ShortcodeParser looks interesting, but there is not much doc, except...

    http://www.silverstripe.org/data-model-questions/show/15084#post296386
    http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/

    ...both of which look like every function you need to define and register - so in the case of the question asked "how to use built in controls like $Now" - I'd say it was easier to change one line, then add a single line function to enable than define all the controls again for short codes. But maybe I don't understand enough of the shortcodes...

    One thing I am very interested in is if there is adding a tinyMCE pugin for a drop down with things like "$Now" or "$FieldName" in it - I am sure this would also be needed for the shortcode example - or would that scaffold the options for the user to select?. Any ideas?

  • joelg
    Avatar
    Community Member
    129 Posts

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

    Hi Swaiba

    True, ShortcodeParser might become to big a job for this issue. I just thought it was a good alternative. I'm using shortcodeparser a lot and it's really easy:

    public function GetMySpecialContent(){
          
    $parser = new ShortcodeParser();

    $parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler')); //This is for normal site links...
    $parser->register('a_short_code', array('Page', 'aFunctionToCall'));
    $parser->register('another_short_code', array('Page', 'anotherFunctionToCall'));

    return $parser->parse($this->Content);
    }

    Happy coding!

    Joel

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

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

    Hi again Joel,

    Both look like they will do the job... How does the user enter the shortcodes? are they something that they must know (i.e. remember) or does this scaffold into the tincyMCE with options the user selects?

  • joelg
    Avatar
    Community Member
    129 Posts

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

    Sorry, no, shortcodes doesn't go into tinyMCE. Unfortunately. The user would have to write:

    [a_short_code text="Do something with this text"]

    or

    [another_short_code id="24"]Some shortcode stuff

    into the Content field of a SilverStripe page or in another field. However these codes could be written into a tab at each page with a LiteralField. That way the user could always have a look at how the shortcodes work...

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