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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

using built in page controls in "Content" area?


Go to End


20 Posts   5677 Views

Avatar
theoldlr

Community Member, 103 Posts

12 February 2011 at 2:47am

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?

Avatar
swaiba

Forum Moderator, 1899 Posts

12 February 2011 at 3:49am

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

Avatar
swaiba

Forum Moderator, 1899 Posts

20 February 2011 at 8:58pm

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

Avatar
joelg

Community Member, 134 Posts

22 February 2011 at 2:40am

Hi

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

Joel

Avatar
swaiba

Forum Moderator, 1899 Posts

22 February 2011 at 3:08am

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?

Avatar
joelg

Community Member, 134 Posts

22 February 2011 at 3:26am

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

Avatar
swaiba

Forum Moderator, 1899 Posts

22 February 2011 at 3:29am

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?

Avatar
joelg

Community Member, 134 Posts

22 February 2011 at 3:33am

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