Page 1 of 1

News title to meta tag og:title in head

Posted: Sun Feb 16, 2014 1:02 pm
by Streamer
Hi,

I want to get news title to meta tag. I made it with smarty and jquery and it works fine with browser. But I want to share news in Facebook and it does not execute javascript when parsing page so it must be done in server side.

So I wrote UDT that reads smarty variable but the problem is that the variable set with news is not available before content has passed so i cannot get it to the head.

Does anyone has solutions to this?

Re: News title to meta tag og:title in head

Posted: Sun Feb 16, 2014 8:00 pm
by Dr.CSS
This has been discussed here quite a few times...

assign a variable to what you want to pass in News template, call the var in the <head>, the pages are processed with the <head> last...

Re: News title to meta tag og:title in head

Posted: Sun Feb 16, 2014 8:09 pm
by velden
First line of your page template:

Code: Select all

{title assign='title'}
This will assign the content of {title} to the variable $title

In the <head> section of your page template:

Code: Select all

<title>{$title}</title>
<meta your facebook og tag content="{$title}">
Note: that the dollar sign is used in {$title}

In your News detail template:

Code: Select all

{assign var='title' value=$entry->title}
This will overwrite the earlier set $title variable with content of $entry->title (which I assume is your news item title).

<head> section is processed AFTER </__body> section of template by CMSMS. So this should work.


Something like that.

Re: News title to meta tag og:title in head

Posted: Mon Feb 17, 2014 7:20 am
by Streamer
velden wrote: <head> section is processed AFTER </__body> section of template by CMSMS. So this should work.
Thanks for your answers!

I found now the solution, i have whole site header in global content block because i have multiple templates that has same header and footer. Those are prosessed earlier and does not work from there, <head> must be in template. So I must put head to the templates.

Re: News title to meta tag og:title in head

Posted: Mon Feb 17, 2014 9:16 am
by velden
Since I learned about template inheritance I don't use GCB for that purpose anymore:

http://www.i-do-this.com/blog/Smarty-te ... -Simple/57