Page 1 of 1
LISE and canonical URL in detail template
Posted: Tue May 31, 2022 3:39 pm
by webform
I can't seem to figure out how i set the canonical url for the LISE detail template.
I'm using this in my LISE detail template:
Code: Select all
{assign var='canonical' value="{root_url}/{$item->url}" scope=global}
and the variable is outputting the correct url but the canonical url from {metadata} is unchanged.
Am i forgetting something?
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 5:08 pm
by DIGI3
It's usually an order of operations thing. Do you have anything in your config.php such as startup_mact_processing set?
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 6:56 pm
by webform
Good thought. But i only have default config except "permissive_smarty" enabled.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 7:00 pm
by DIGI3
You'll need to do a bit of troubleshooting then, output the variable in various parts of your template and see where it's getting set, and where it's changing. Do an admin search for 'canonical', and check all templates to make sure it's not being reset somewhere else later.
Perhaps also share your metadata entries, and a url if possible. I'm also going under the assumption you're on the latest version, but advise if that's not the case.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 7:50 pm
by webform
Yes, i'm using latest version (CMS MS 2.2.16).
I don't have the variable nowhere but in my LISE detail template and the default News default template.
I've created a page with the default News template and the page also doesn't display the canonical url for the news item, but only the url for the page url.
I've inserted the variable {$canonical} in all 3 zones in the base template and the canonical url outputs correctly. It's only the rel="canonical" from {metadata} that is ignoring the set variable in the module detail template.
If i'm using the old {CGHeadMaster} module i can override default canonical url from {metadata}
Code: Select all
{cghm_config_set key='canonical' val=$canonical|default:''}
but who knows how long that solution will work.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 7:56 pm
by DIGI3
I would just add the meta to your page template instead of in the {metadata} section in admin then. It's possible that gets processed first, I haven't tested. Just add the line right before/after you call {metadata}.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 8:03 pm
by webform
It's not the metadata section in admin but the {metadata} tag in the page template that outputs the rel="canonical" tag, there is ignoring the set canonical variable in the LISE and NEWS detail template.
Only with {CGHeadMaster} and {cghm_config_set key='canonical' val=$canonical|default:''} it seems the {metadata} tag is accepting the canonical url of the LISE and NEWS module.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 8:08 pm
by DIGI3
The {metadata} tag just outputs what's in the admin metadata section. Because this is (likely) processed before the module tag, it can't know it's been set elsewhere. Cut the line from that section and put it in your template. I usually put something like this in the head of my template:
Code: Select all
{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}
as the <head> section is processed after modules, it will have access to variables set in modules with scope=global.
I'm not familiar with the CG module but as it's been abandoned by its author I wouldn't suggest using it.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 8:20 pm
by webform
I don't have that content in my metadata section in admin only
Code: Select all
<meta name="Generator" content="CMS Made Simple - Copyright (C) 2004-2018. All rights reserved." />
So i assumed the rel="canonical" came default from the {metadata} tag in the template.
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 8:28 pm
by DIGI3
Nope, it only sets what's in the admin section for it, plus it adds a <base> tag unless told not to. Your canonical tag must be in a template or module somewhere (perhaps CGHM sets one by default?)
Re: LISE and canonical URL in detail template
Posted: Tue May 31, 2022 8:34 pm
by webform
I think your right!
It must be CGHeadMaster that set canonical tag by default and i must just have forgotten i've removed the tag from the metadata section back then i've created the site a couple of years ago.
Thanks for your time and patience.