Page 1 of 1
How to get Facebook Open Graph to grab dynamic title info??
Posted: Wed Apr 25, 2012 7:34 pm
by skarni
I am currently using CMSMS 1.10.3 "Hyacinthe".
I commonly share links from my calguys calendar to facebook. Open Graph meta data likes for links to have specific titles, urls and all of that. Since Calguys calendar (among things) produces dynamic titles, I cannot simply enter a title for each calendar entry.
I have the following in my template metadata:
Code: Select all
<meta property="og:title" content="{$pagetitle}" />
I do not have a property for the url as it too is dynamic.
The title is generated with the code above, but when the url is shared on facebook in a post, the title is replaced with the root url?! See image attached image.
How do I set my calendar page template up to be facebook friendly, and retain its dynamic event titles, urls and so on? I'm a terrible coder.
Try to see how it would share on your facebook, should look like the photo. I've no idea what to do.
http://www.tourpikecounty.com/index.php ... turnid=168
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Wed Apr 25, 2012 8:04 pm
by calguy1000
actually, this is quite simple... and can work with any module template, and page template... I have posted about this numerous times.
Since CMSMS always processes the HTML body through smarty before it processes the HTML head it is possible to create variables in the body template, or in any template called from within the body... and use them within the head section.
All you need to do is copy the data you need into another variable... then in the head section of your page template, check if that variable is set, and do something accordingly.
a: In your CGCalendar event template, or CGBlog / News / Products / Listit2 (see a pattern here) detail template do something like this (variable names may change depending on the module).
{assign var='mytitle' value=$event.event_title}
Code: Select all
b: In your page template do something like this:
[code]{if isset($mytitle)}
<title>{$mytitle} | {sitename}</title>
<meta property="og:title" content="{$mytitle}" />
{else}
<title>{title} | {sitename}</title>
{/if}[/code]
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Tue Feb 12, 2013 1:48 pm
by kupido
Hello
had a problem:)
it may be that since 1.11.x that workaround don't work.
I used 1.11.3 and now 1.11.4
In Google Chrome it changed the title.
But with opera and Firefox it doesn't work, also Facebook doesn't work:(
Any idea?
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Thu Feb 14, 2013 9:15 am
by oliverseddon
Hi,
Not wanting to blow my own trumpet, but have you tried MetaMax?
It's built to make all of this stuff as easy to implement as possible. It uses a similar theory for getting the page's title mentioned by Calguy, but you add the page title variable into MetaMax rather than into the head of your template.
It also has an option to specify the OG image used by Facebook too.
I'm on the CMS IRC chat if you have any questions or need any help implementing it.
Thanks
Oliver
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Thu Feb 14, 2013 11:10 am
by kupido
thanks for this tip
but does also not work.
had in the newsdetailtemplate, at the beginning:
Code: Select all
{capture name='mypagetitle'}
{$entry->title}
{/capture}
and in MetaMax - Page title smarty tag:
{$mypagetitle}
and he show me only the standard title
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Thu Feb 14, 2013 11:17 am
by oliverseddon
Okay,
I would tend to just assign, rather than capture in the news detail.
So, at the top of the newsdetail template add:
Code: Select all
{assign var='pagetitle' value=$entry->title}
You then just add
pagetitle in the MetaMax page title input, no dollar or curly brackets.
In your page template you should then have something like this:
Code: Select all
{capture assign='pageContent'}{content}{/capture}
{if !isset($pagetitle)}
{capture assign='pagetitle'}{title}{/capture}
{/if}
{MetaMax}
You would then need to replace your standard
call in the template with
as this has been captured as a variable with the above code.
Are you using MetaMax to create you Doctype, HTML, Head tags etc?
Re: How to get Facebook Open Graph to grab dynamic title inf
Posted: Thu Feb 14, 2013 11:38 am
by kupido
Thank oliver
thats work:)
No i had at the moment the standard config from metamax:)
but he has checked meta tags
generate base tag
standard meta tags
but in the tab html tag settings al checkbox off
Has it any benefits for me:) when i use this
One question for the description
I put
Code: Select all
{assign var="mydescription" value=$entry->summary|strip_tags|truncate:200}
also on the top from newsdetailtemp
and in metamax Name of page description content block:
mydescription
but had no description.
When i use your Code
{capture assign='pageContent'}{content}{/capture}
and changed {content} to {$pageContent}
he show me no content on the Site