Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Display a page using different templates

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

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

Page: 1
Go to End
Author Topic: 7289 Views
  • eguru
    Avatar
    Community Member
    6 Posts

    Display a page using different templates Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Display a page using different templates Link to this post

    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?

  • saimo
    Avatar
    Community Member
    67 Posts

    Re: Display a page using different templates Link to this post

    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';

  • eguru
    Avatar
    Community Member
    6 Posts

    Re: Display a page using different templates Link to this post

    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

  • saimo
    Avatar
    Community Member
    67 Posts

    Re: Display a page using different templates Link to this post

    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.

  • eguru
    Avatar
    Community Member
    6 Posts

    Re: Display a page using different templates Link to this post

    Thanks saimo for your help. Works a treat.

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

    Cheers

    7289 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.