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, Ed, biapar, Willr, Ingo, swaiba

Render data with a different template

Go to End

3 Posts   2288 Views


Community Member, 20 Posts

22 May 2012 at 2:21am

Hi Guys,

I try to speed up a bloated homepage and catch some content of tabs on demand only.

Therefor I need to render the content of some tabs without loading all of the page, which is really slow because of CURL requests. I experimented with renderWith, it's working but it feels wrong.

First I check for an action which I use to fetch the tab content:

$params = $this->getURLParams();

if ($params['Action']) {
if ($params['Action'] == 'latestsamples') {
echo $this->renderWith('LatestBooks');

Since I couldn't make the page stop rendering the HomePage Template I just print the returned string and shut it off.

The code will do for now, but there are more tabs and I'd like to do it i a proper way. Can somebody help me out?



Community Member, 33 Posts

22 May 2012 at 5:17pm

Maybe you can AJAX the tab requests... something along the lines of:


	function latestsamples() {
		if($this->isAjax) {
			return $this->renderWith('LatestBooks');
		else {
			return Array();

	public function init() {

		if(Director::is_ajax()) {
			$this->isAjax = true;
		else {
			$this->isAjax = false;



	public function MyBooks() {
		return $books;



		<div id="tab-container">
			<div id="ajaxTab">

		<a href="{$Link}latestsamples" onclick="$('#ajaxTab').load('$Link' + 'latestsamples'); return false;">
			Latest Books


<h2>Latest Books</h2>
<% control MyBooks %>
<% end_control %>

I'm not sure how I got it to work without having JS enabled and then maybe it's better to use jQuery for the click binding.. but as a starting point maybe this will help.


Community Member, 20 Posts

22 May 2012 at 7:31pm

Edited: 22/05/2012 11:26pm

I just added the function latestsamples to the controller and it's working like a charm.

Thank you for your effort, you helped me a lot.