Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Three links pointing to the same page - Need Title to change.

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: 1457 Views
  • Todd
    Avatar
    31 Posts

    Three links pointing to the same page - Need Title to change. Link to this post

    Hi Guys,

    I'm sure this is very easy, but I just can't put my head around it.

    I have three static links that I wish to point to the same page. The only thing that needs to change is the title in the header section.

    Normally I would add the variable in question to the link, like www.company,com/page/?Title='sometitle' , perform a $_GET and be done with it. I just haven't figured out how to do it within the Silverstripe scheme (which I like by the way).

    Many thanks,

    Todd

  • Sigurd
    Avatar
    Forum Moderator
    628 Posts

    Re: Three links pointing to the same page - Need Title to change. Link to this post

    One idea is to make child methods so that its

    www.mysite.com/contactus/rahrah

    then you add a method called rahrah (which subclasses page?) that updates Title appropriately.
    Look through the tutorial at how methods and subclassing work.

    The problem with /contactus/?pagetitle=RahRah is that its a bit ugly, and people can exploit it with things like ?pagetitle="I hate your mum" or "This site sucks" etc.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Three links pointing to the same page - Need Title to change. Link to this post

    I think you can do Sig's method like this:

    so, mysite.com/about-us/cooltitle provides a custom $Title field. You can add more items to the array to make more fields, if you require it.

    class Page extends SiteTree {
    ...
    }

    class Page_Controller extends ContentController {

    function cooltitle() {
    return array(
    'Title' => 'yay'
    );
    }

    }

    Hope this helps!

    Sean

  • Todd
    Avatar
    31 Posts

    Re: Three links pointing to the same page - Need Title to change. Link to this post

    Hi Sigurd, Sean,

    Many thanks. Maybe I'm an idiot, but I'm still not getting it. Do I create a cooltitle.php file and put the above information into it, then call the method as a control in the contact.ss file, or do I need to create a cooltitle.ss file and call it from there, or neither?

    Thanks,

    Todd

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Three links pointing to the same page - Need Title to change. Link to this post

    Hi there,

    You create cooltitle() in your Page.php file, then call it as contact-us/cooltitle

    So, you can then go <a href="{$Link}cooltitle">Cool stuff</a> in the template (Page.ss).

    contact-us is just a standard page. If contact-us uses a page type other than Page.php then you can put it on that one, otherwise just put it on Page.php.

    Note that you can call cooltitle() on any page if you put it in Page.php, because everything inherits that.

    Hope this helps!

    Sean

  • Todd
    Avatar
    31 Posts

    Re: Three links pointing to the same page - Need Title to change. Link to this post

    Hi Sean,

    Thanks a lot. Both for the code and the explanation. It worked perfectly.

    Todd

    1457 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.