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.

Archive /

Our old forums are still available as a read-only archive.

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

Display a page using different templates


Go to End


6 Posts   8098 Views

Avatar
eguru

Community Member, 6 Posts

28 May 2008 at 2:07pm

Hi,

I am wondering if it is possible to display a page using different templates. The requirement I have is to be able to pass a template name using a parameter on the URL. e.g.

http://www.mysite.com/news?template=news_complete
http://www.mysite.com/news?template=news_summary

I assume you can do this using $RenderWith in the Page_Controller definition in the page .php class file but I am not sure how to access the variables on the URL.

Thanks for your help in advance

Cheers

Avatar
Willr

Forum Moderator, 5523 Posts

28 May 2008 at 7:28pm

how to access the variables on the URL...

same as normal as would have thought - using $_GET['template'] why do you want to send / set templates this way?

Avatar
saimo

Community Member, 67 Posts

28 May 2008 at 7:56pm

Edited: 28/05/2008 7:56pm

To select the theme with the URL parameter:

//theme settings
if(isset($_GET['theme'])) {
   $theme = $_SESSION['theme'] = $_GET['theme'];
}
else {
   $theme = 'yourdefaultthemehere';
}

or, to make it persistent for the current session:

//theme settings
if(isset($_GET['theme'])) {
   $_SESSION['theme'] = $_GET['theme'];
}

$theme = isset($_SESSION['theme']) ? $_SESSION['theme'] : 'yourdefaultthemehere';

Avatar
eguru

Community Member, 6 Posts

28 May 2008 at 8:08pm

Thanks for the info. I'll give it a go later tonight.

The reason I am doing this is that I need to display a page differently depending on where it is displayed. The site I am currently building requires that when a page is linked to from a particular page it will be displayed in a popup window, in which case the only data that needs to be displayed is the content, but if the page is displayed from other pages then the entire page needs to be displayed.

The popup window library I am using requires that you pass it a URL to display in the window. In this case I only need to display the content, not the entire page. One way of seeing of how this could be done was to pass the template that the page should be displayed with as a variable.

If there other ways more in line with SilverStripe coding then any help with these would be appreciated..

Cheers

Avatar
saimo

Community Member, 67 Posts

29 May 2008 at 12:37am

In that case I would suggest a different method. Please correct me on this willr :).

Create a new root template named Page_popUp.ss that only contains the absolutely neccessary html and the $Layout variable. You can then call this template by appending /popUp to the url.

Avatar
eguru

Community Member, 6 Posts

29 May 2008 at 10:10am

Thanks saimo for your help. Works a treat.

Wonder what other little treats I can find with this CMS.

Cheers