17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 7154 Views |
-
Display a page using different templates

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_summaryI 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
-
Re: Display a page using different templates

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?
-
Re: Display a page using different templates

28 May 2008 at 7:56pm Last edited: 28 May 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';
-
Re: Display a page using different templates

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
-
Re: Display a page using different templates

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.
-
Re: Display a page using different templates

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
| 7154 Views | ||
|
Page:
1
|
Go to Top |


