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?
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.
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries
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
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
Hi
Maybe all of this could be done with a ShortCodeParser... Much easier I think.
Joel
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?
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
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?
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...
- Previous 10 entries
- 1
- Page 22(current)
- 3
- Next 10 entries