21301 Posts in 5735 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 3005 Views |
-
Generator HTML Tag

29 June 2010 at 4:05am
Hi All,
Just noticed that Silverstripe 2.4 now gernerates a generator HTML tag in the sites HEAD. Though this doesn't bother me for most sites, we have some high security sites built in Silverstripe that I would feel more comfortable about removing this for.
Is this possible, and if so, how?
Cheers,
Mo
-
Re: Generator HTML Tag

29 June 2010 at 10:05am
Copy the MetaTags() function from SiteTree.php to your own Page.php. Then you can customize it as much as you need.
-
Re: Generator HTML Tag

29 June 2010 at 7:05pm
Oooo, I have always wondered how you customise MetaTags, never really put a lot of time into working it out though.
Cheers Willr!
Mo
-
Re: Generator HTML Tag

30 June 2010 at 7:09am
Hi there, so my site works fine in every browser except for explorer (using IE7). My site header looks like this:
<% base_tag %>
<title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> » $SiteConfig.Title</title>
$MetaTags
<link rel="shortcut icon" href="/favicon.ico" />I like how the generator works and i would like to include it in the header. Unfortunately explorer is displaying the Custom Meta Tags in the public header of my site.
The only way i have been able to fix this is by deleting $MetaTags line from the header code but as i said, i would like to include the meta tags and the problem is with IE only.
Can someone point to how I can fix this?
Thank you, P.
-
Re: Generator HTML Tag

30 June 2010 at 10:22am Last edited: 30 June 2010 10:25am
I like this post, because I had thought about this before, but did not know where to go to customize it a little...
I had a client ask about generating Canonical URLs for their Silverstripe site....now I though to myself - with SS you don't really need Canonical URLs because the SS URLSegment is so sweet and simple. (Other CMS struggle at this with params etc)....
Anyways I had created a method in the Page class that generates the Canonical URL, and then when I saw this post, I thought why not customize the MetaTags function and have it generate it instead of putting the call in the .ss template.
So here goes some code.
1. Create a GetCanonical Method in your Page class controller (there are bunch of if/else statement to try and handle actions/IDs/OtherIDs in the NestedURL structure of 2.4)
function GetCanonical() {
if (Director::urlParam('Action')) {
$action = Director::urlParam('Action');
$parameterID = urlencode(Director::urlParam('ID'));
$parameterOtherID = urlencode(Director::urlParam('OtherID'));
if (strcmp($action, $this->URLSegment) == 0 && empty($parameterID) ) {
return false;
} else if (strcmp($parameterID, $this->URLSegment) == 0) {
return false;
} else if (strcmp($action, $this->URLSegment) != 0 && empty($parameterOtherID)){
return $action . '/' . $parameterID;
} else {
return $parameterID . '/' . $parameterOtherID;
}
}
}2. Add this simple line to your MetaTags function
$tags .= "<link rel=\"canonical\" href=\"" . $this->AbsoluteLink() . $this->GetCanonical() . "\" />\n";
This should work with simple URLs as well as accomodate the case of DataObjects being displayed with action/ID functionality. Please feel free to take it, use it, or even provide feedback on a better and more efficient means to achieve this.
- Ed
-
Re: Generator HTML Tag

3 October 2010 at 7:14am
What about custom controller?
Director::addRules(50, array('shop/$Action/$ID' => 'Products_Controller'));
class Products_Controller extends Page_ControllerI tried:
public function MetaTags($includeTitle = TRUE){
$tags = "<title>TEST</title>\n";
$this->extend('MetaTags', $tags);
}
and got nothing -
Re: Generator HTML Tag

23 September 2011 at 4:32am Last edited: 23 September 2011 5:10am
2 things to add to the Canonical discussion...
1) If you're just adding a tag, it's simpler to pull it into the .ss file than override the MetaTags function. (The original reason overriding MetaTags was recommended in this thread was to remove a tag.)
2) The canonical tag should include the domain name if there's a chance that multiple domains or subdomains point to the same page, so the code below uses protocolAndHost.
In the Page.php define...
function CanonicalURL() {
return Director::protocolAndHost() . $this->Link();
}...then in Page.ss...
<head>
<% base_tag %>
<link rel="canonical" href="$CanonicalURL" />
$MetaTags
</head>Note that this doesn't include edk's solution for dealing with virtual pages (good point!), but the two could easily be merged...
-
Re: Generator HTML Tag

29 September 2011 at 2:09am
Hi, I tried to use the function GetCanonical by -Ed,
so i added
- function GetCanonical() to the page.php
- $tags .= "<link rel=\"canonical\" href=\"" . $this->AbsoluteLink() . $this->GetCanonical() . "\" />\n"; to SiteTree.phpand i also added the code from inCharge
function CanonicalURL() {
return Director::protocolAndHost() . $this->Link();
}
to page.php<link rel="canonical" href="$CanonicalURL" />
to the Page.ssBut i only geht an empty <link rel="canonical" href="" />
Can you help?
Best regards bastiR
| 3005 Views | ||
| Go to Top | Next > |





