Page 1 of 1

How do I add URL alias to {title}

Posted: Sat Nov 30, 2013 12:30 pm
by CapereSpiritum
Hi folks

Anyone know how to add a URL alias from Products into the meta title?

Just want to show a relevant title in the mata tag for each product.



Just an aside....
CRACKING result in the Bitnami contest. Streets ahead of the 'competition'... Got my vote in on Thursday :-)

Re: How do I add URL alias to {title}

Posted: Sun Dec 01, 2013 1:56 pm
by Rolf
Yeah, we did good ;) Thanks for voting

About your question.
You can add in the top of your module detailtemplate something like:

Code: Select all

{assign var='custom_url' value=$entry->url}
{assign var='custom_title' value=$entry->title}
It depends on the module you use...

You need to let the content processed by Smarty like marked here as a)

Code: Select all

{strip}
   {process_pagedata}
   {content assign='maincontent' label='My content block'} <------ a)
{/strip}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

< head>
<meta name="description" content="{if $custom_title != ''}{$custom_title}{else}{title}{/if}" /> <------ b)
< /head> 

< body>
<div id="content">{$maincontent}</div> <------ a)
< /body>

< /html>
You now can use in your template strings like {$custom_url} and {$custom_title} marked above as b)

Hope this helps

Rolf

Re: How do I add URL alias to {title}

Posted: Sun Dec 01, 2013 8:29 pm
by velden
I even think that you don't need the a) part as the content in body is processed before the head-part is. Note that if you don't use a) that b) should also be changed to 'normal'.

Processing order is: ...well read it here

Re: How do I add URL alias to {title}

Posted: Sun Dec 01, 2013 9:07 pm
by Rolf
velden wrote:Processing order is: ...well read it here
Correct, but the method I described works in any template situation/order.

Re: How do I add URL alias to {title}

Posted: Sun Dec 01, 2013 10:42 pm
by Jo Morg
Rolf wrote:
velden wrote:Processing order is: ...well read it here
Correct, but the method I described works in any template situation/order.
It does because a) is needed.

The 1st area being processed is outside both < head > and < body > tags, and (if I understand correctly the article) also outside the < html >. This means that, as Rolf pointed out and is explicit on the article referred by the link, the proper place to do most assignments is even before the < html > tag. There are exceptions but very few.