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:

Template Questions /

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

Unique Template

Go to End

5 Posts   983 Views


Community Member, 66 Posts

21 November 2012 at 10:12pm

SilverStripe 2.4.7

I was wondering if it is possible to create a completely unique template within SS?

What I want to do is scrape the markup from another site, echo out that markup and put a control block in one of the divs. I have the scraping working in php but I'm not sure how to proceed. Should this be a method in the controller that I call within the URL?

I have tried a few things but the default CSS of page gets applied. My knowledge on templates isn't extensive enough to know whether this is even possible.

Thanks in advance.


Community Member, 79 Posts

22 November 2012 at 7:21am

Hi there,

In your method you can use the ->renderWith('templateNameHere') to allow you to render the output with a specific template. This way you can set the template up however you like.

For example

return $this->customise(array('AllBooks' => $AllBooks))->renderWith('MyCustomTemplateName'); 

You can pass in as many DataObjectSets or ArrayData as you like for the template.

return $this->customise(
                    'absoluteURL' => Director::absoluteBaseURL(),
                    'isFollowing' => $this->isUserFollowing($URLSegment),
                    'profileData' => $profileData, 
                    'activityData' => $this->getUserActivity($URLSegment),
                    'collectionData' => $collectionData, 
                    'MenuTitle' => $MenuTitle, 
                    'URLSegment' => $URLSegment,
                    'checkUser' => $this->checkUser()

As you can see with this second one I am passing in a lot more information for the template (but on this occasion I am using the default template). But all I would need to do is add this to the code and it would render with a custom template



Community Member, 66 Posts

22 November 2012 at 10:23pm

That's great. Thanks. But will that template be free from the default CSS in SilverStripe? I think I need to set up a method in my page controller to scrape the html I need, return it as strings, use control blocks to add those strings to the template and then use a control block to pull data out of my database.

It seems logical enough in my head but anything I put in the template is styled with BlackCandy's CSS.


Community Member, 79 Posts

23 November 2012 at 10:54am

You'll need to have a look at where the stylesheet is being included. Is it included in Page.php?


Community Member, 66 Posts

23 November 2012 at 11:52pm

Yes, it is. Thanks for your help. I chose an alternate solution for this but it's good to know how to show a different template anyway.