GALLERY og:graphs meta data

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

GALLERY og:graphs meta data

Post by Brandt »

Hello CMS Made Simplers,

I am working on the Gallery Module; all is working great, though I would like to change something and this might be a future item for the module aswell.

In the Gallery, changing the template there are three text-areas:
1. Template code:
2. Template CSS-stylesheet:
3. Template JavaScript:

Now I don't need no JavaScript, but I would like some Facebook og:graphs meta data. So I copied some meta data and put it in the 'Template JavaScript:' text-area, saved and it worked. Tested it with the Facebook debugger and all is well.

Now I did this so I could have dynamically meta data. I wanted to achieve this using the Gallery tags like this for instance:

Code: Select all

<meta property="og:image" content="http://studiomik.nl/{$image->thumb|escape:'url'|replace:'%2F':'/'|replace:'thumb_':''}">
But the information is not changed, I see the tag instead. Is there a way I can change the text-area so it can read the tag? Or in which file should I look for in the Gallery Module folder?

Anyway, I think this might also be a great future item for the Gallery Module. So when a new page is created through the Gallery Module and if this page is shared on Facebook or Twitter it will get its own information.

Thanks in advance,

Joep
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: GALLERY og:graphs meta data

Post by velden »

It can be done.

I would set some Smarty variables inside the gallery template and use those later on in your page template in the head section.

Don't use the javascript area.
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

Hi Velden,

Thank you for your reply. I don't understand what you are saying here. How do I get the smarty variables in the head of my page using the Gallery Module?
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm

Re: GALLERY og:graphs meta data

Post by Jeff »

Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

Thank you Jeff. How can I combine this with the Gallery Module?
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

I am experimenting, but without succes; I thought this might get me somewhere:

In the Gallery Module > Template:

Code: Select all

{$images->file assign=foo}
In the <head> section of the page:

Code: Select all

<meta property="og:image" content="{$foo}" />
Can anybody put me on the right track? I want the url from the first image of a Gallery list to be as an og:image meta data.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: GALLERY og:graphs meta data

Post by velden »

What version of CMSMS do you use?
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

A classic: CMS Made Simple™ 1.11.6 “Merchant”
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: GALLERY og:graphs meta data

Post by velden »

In your 'example' try:

Code: Select all

{assign var=foo value=$images->file}
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

Thank you Velden!

It works - though instead of the first image I get the last one of the list.

Code: Select all

<ul class="gallerylist">
{foreach from=$images item=image name=img}
<li>
<img src="{$image->thumb|escape:'url'|replace:'%2F':'/'|replace:'thumb_':''}" alt="{$image->titlename}" />
</li>

{assign var='g_prevdepth' value=$image->depth}
{/foreach}
</ul>

{assign var=foo value=$image->thumb|escape:'url'|replace:'%2F':'/'|replace:'thumb_':''}
And the same when using

Code: Select all

{assign var=foo value=$image->file}
But I am on the right track…
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: GALLERY og:graphs meta data

Post by velden »

Of course you get the last image.

Try (untested):

Code: Select all

<ul class="gallerylist">

{assign var=foo value=$images[0]->thumb|escape:'url'|replace:'%2F':'/'|replace:'thumb_':''}

{foreach from=$images item=image name=img}
<li>
<img src="{$image->thumb|escape:'url'|replace:'%2F':'/'|replace:'thumb_':''}" alt="{$image->titlename}" />
</li>

{assign var='g_prevdepth' value=$image->depth}
{/foreach}
</ul>
Note that using the thumb image might not be the best idea (depends on thumb size). Facebook and such want the Open Graph image to be rather large.

Consider using the $images[0]->file and e.g. CGSmartImage module to resize.

OR use a dedicated 'Open Graph' Gallery template for 'Template for module-calls to a single image' and set the appropriate thumbnail size for that specific template. Then store the image ID in your variable. In the <head>-section call the Gallery module using the img=<id> parameter and make sure the template itself outputs nothing.
Calling the module makes the $image variable available in the page template (cmsms 1.11.x !!)

Some ugly code from an older site I built:

Code: Select all

{* call gallery single image so we get IMAGE object *}
	{Gallery img=<image ID>}
        {root_url assign=rooturl}
	{assign var=og_image value="`$rooturl`/`$image->thumb`"}
Note the ` around the variables are backticks and NOT single quotes. Probably just {} would work too:

Code: Select all

{* call gallery single image so we get IMAGE object *}
	{Gallery img=<image ID>}
	{assign var=og_image value="{root_url}/{$image->thumb}"}
Brandt
Forum Members
Forum Members
Posts: 55
Joined: Fri Mar 05, 2010 10:04 am

Re: GALLERY og:graphs meta data

Post by Brandt »

Thanks Velden!

The solution with

Code: Select all

{assign var=metaimage value=$images[0]->file}
works flawlessly.

I will look and try to understand exactly your 'single image' code.

Thanks again!

Joep
Locked

Return to “Modules/Add-Ons”