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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Short code to list dataobjects [solved]

Go to End

3 Posts   1057 Views


Community Member, 68 Posts

6 November 2011 at 3:14am


In Page.php :

class Page extends SiteTree {
public static $has_many = array(
'Chapters' => 'Chapter'

In Chapter.php :

class Chapter extends DataObject {
public static $db = array(
'Title' => 'Text',
'Content' => 'Text'
public static $has_one = array(
'Photo' => 'Image',
'MyPage' => 'Page'

In templates/Includes/ :

<% control Chapters %>
<img <% control Photo %><% control SetWidth(440) %>src="$URL" height="$height" width="$width"<% end_control %><% end_control %> alt="$Title" />
<% end_control %>

I would like to enable my client to include the template wherever he wants in the content editor with a short code ( -

But I have no idea of what to put in my "shortcodehandler" function in Page.php.

Could anyone give me a hint ? Thank you !



Forum Moderator, 5523 Posts

6 November 2011 at 1:04pm

SSbits has a good tutorial on using short codes - and rendering into a template.


Community Member, 68 Posts

6 November 2011 at 3:18pm

Thank you Willr !

I finally found a solution that works ; in page.php :

static function chapterShortCodeHandler(){
	$current = Controller::curr(); 
	return $current->renderWith('Chapter');