[solved] Generating og:image tag

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

[solved] Generating og:image tag

Post by pwg »

Hi,
More meta tag issues. Sorry.
I'm having trouble getting the "correct" og:image tag code to be produced on my assigned content.
I can see why its not working, but I'm not sure (well have no idea) how to fix it.

Any help appreciated.

At the top of my template I have:

Code: Select all

{strip}
{process_pagedata}
{content assign='main_content'}
{content block='main_image' label='Main_Image' assign='main_image'}
{$main_image} is used as the image content block, and my meta code is

Code: Select all

<meta property='og:image' content='{if ! empty($main_image)}{$main_image}{else}path to default/uploads/images/logo.png{/if}'/>
Which produces all of the HTML imputed into the main_image content block, including alt and title info.

At the moment I output:

Code: Select all

meta property='og:image' content='<img title="title" src="uploads/images/company/main.jpg" alt="title">'/> 
How do I set it so it just produces the image source code? And is this the best way of assigning content and getting the code for the og:image tag?

Thanks again for any help.

Cheers,

Paul
Last edited by pwg on Wed Nov 26, 2014 6:03 pm, edited 1 time in total.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Generating og:image tag

Post by paulbaker »

Don't you want a content_image tag? Rather than a content block.

http://docs.cmsmadesimple.org/tags/core/content_image

Then you can use this parameter:
urlonly - output only the url to the image, ignoring all parameters like id, name, width, height, etc.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: Generating og:image tag

Post by pwg »

Thanks Paul, looks great, however I tried your suggestion, but when I go to edit the content in the admin section, using the tag {content_image block='image1'} in the template, where you would expect to see the content box is the error: "Error retrieving file list"

Screenshot below:
Image

Do you happen to have any ideas?

Cheers,

Paul
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Generating og:image tag

Post by paulbaker »

Try

Code: Select all

{content_image block='image1' dir='fbimage/home'}
Where uploads/fbimage/home is the directory where the images suitable for this position will be. dir should be relative to uploads directory.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: Generating og:image tag

Post by pwg »

Thanks again Paul, all is good and working.
I have it set like this:

Code: Select all

{content_image block='fb_image' dir='images/recipes' label='FB_Image' assign='fb_image' urlonly='foo'}
Is the urlonly=’foo’ the right way to add that parameter? It works, but it was just a guess.

Thanks again - and I guess also , is it possible to do things so I can use the WYSIWYG editor, to navigate to files, as the drop only appears to contain files within that folder, meaning that I can use page alias, as long as images are in corresponding folders, or have a lot of templates?
Or am I completely missing the point?

Cheers,

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

Re: Generating og:image tag

Post by velden »

Is the urlonly=’foo’ the right way to add that parameter? It works, but it was just a guess.
Probably any value not being 0 or false will work.
is it possible to do things so I can use the WYSIWYG editor, to navigate to files, as the drop only appears to contain files within that folder, meaning that I can use page alias, as long as images are in corresponding folders, or have a lot of templates?
Or am I completely missing the point?
It wouldn't make sense to produce a template for every single page. If you want to use the page alias then skip the whole content_image tag and link to {uploads_url}\images\{$page_alias}.jpg
Of course you need to make sure that those .jpg images (e.g. recipes.jpg) do exist in the uploads\images directory in that case.

But if you want a fancy solution have a look at GBFilePicker module. Read it's help to learn how to use it as a content block in your template. Combine it with CGSmartImage module to resize images to fit the OpenGraph' needs.
That's how I do it.
Last edited by velden on Wed Nov 26, 2014 11:20 am, edited 1 time in total.
Reason: typo
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Generating og:image tag

Post by paulbaker »

velden answered better (and quicker) than I could ;)
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: [solved] Generating og:image tag

Post by pwg »

Many thanks guys, really appreciate the help.

Installing GBFilePicker now to read the help and have a go at getting it working.

Cheers,

Paul
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: [solved] Generating og:image tag

Post by Rolf »

Code: Select all

{if ! empty($main_image)}{$main_image}{else}path to default/uploads/images/logo.png{/if}
Should work too

Code: Select all

{$main_image|default:'uploads/images/logo.png'}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “The Lounge”