Use {module_action_link} to create canonical URLS

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Use {module_action_link} to create canonical URLS

Post by calguy1000 »

Some modules create smarty variables for canonical urls from thier various detail views. News is one of them. Some however do not. (including I am sorry to say, some of mine).

We all know that the <link rel="canonical" href="some url"/> tag is the way to tell the search engines the one true URL for a page. So, making sure its filled in is important.

CMSMS's built in templates have a tag like this in their head section:

Code: Select all

{if isset($canonical)}<link rel="canonical" href="{$canonical}" />{elseif isset($content_obj)}<link rel="canonical" href="{$content_obj->GetURL()}" />{/if}
This logic says if the smarty variable 'canonical' exists, then use it to build the canonical link. otherwise, use the current content object. Also, remember CMSMS processes the body portion of the page template through smarty before the head portion of the page template is parsed through smarty. So therefore, we can set variables in any template that is processed in the body, and those variables will be available in the head portion of the page template.

News has an {$entry->canonical} variable in its detail view. And the default detail template has a line like: {assign var='canonical' value=$entry->canonical} to ensure that our 'canonical' value is set properly for use when the page template's head section is processed.

If a variable like this isn't available, you can easily create one, just by re-creating the URL. Sometimes you can use the {get_current_url} plugin provided by the CGExtensions module. However, if there is alot of ajax going on this may work the way you want it to. That's where the {module_action_link} plugin comes in. It is provided in the CGSimpleSmarty module.

Adding a line like:
{module_action_link module=CompanyDirectory action=details compid=$entry->id urlonly=1 assign=canonical} into your detail template will generate the pretty url necessary for the canonical view.

I encourage you to look at the help of the CGSimpleSmarty module to see all of the parameters for this, and the other smarty plugins.

Hint: some js for ajax:
var url = '{module_action_link module=CompanyDirectory action=details compid=5 urlonly=1 jsfriendly=1}&showtemplate=false';
$('#somediv').load(url);
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Use {module_action_link} to create canonical URLS

Post by psy »

Thanks Calguy
You can also apply the same smarty logic in the SEOTools2, Page title & Meta information tab, Additional Meta tags textarea (full Smarty support).
Post Reply

Return to “Tips and Tricks”