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.

General Questions

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

using built in page controls in "Content" area?


20 Posts   3364 Views


12 February 2011 at 2:47am Community Member, 103 Posts

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?


12 February 2011 at 3:49am Forum Moderator, 1796 Posts


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) %>
<% end_control %>

in Page_controller ...

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


20 February 2011 at 8:58pm Forum Moderator, 1796 Posts

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


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







22 February 2011 at 2:40am Community Member, 129 Posts


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



22 February 2011 at 3:08am Forum Moderator, 1796 Posts

Hi Joel,

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

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


22 February 2011 at 3:26am Community Member, 129 Posts

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!



22 February 2011 at 3:29am Forum Moderator, 1796 Posts

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?


22 February 2011 at 3:33am Community Member, 129 Posts

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

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


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