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.

Archive

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

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

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


Reply

6 Posts   1525 Views

Avatar
Todd

26 October 2007 at 7:02am (Last edited: 26 October 2007 7:22am), 31 Posts

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

Avatar
Sigurd

26 October 2007 at 9:31am Forum Moderator, 628 Posts

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.

Avatar
Sean

27 October 2007 at 1:53am (Last edited: 27 October 2007 1:54am), Forum Moderator, 921 Posts

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

Avatar
Todd

30 October 2007 at 9:37am 31 Posts

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

Avatar
Sean

30 October 2007 at 3:18pm Forum Moderator, 921 Posts

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

Avatar
Todd

30 October 2007 at 4:35pm 31 Posts

Hi Sean,

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

Todd