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

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


Go to End


6 Posts   1839 Views

Avatar
Todd

31 Posts

26 October 2007 at 7:02am

Edited: 26/10/2007 7:22am

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

Forum Moderator, 628 Posts

26 October 2007 at 9:31am

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

Forum Moderator, 922 Posts

27 October 2007 at 1:53am

Edited: 27/10/2007 1:54am

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

31 Posts

30 October 2007 at 9:37am

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

Forum Moderator, 922 Posts

30 October 2007 at 3:18pm

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

31 Posts

30 October 2007 at 4:35pm

Hi Sean,

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

Todd