Page 1 of 1

[solved] Generating og:image tag

Posted: Tue Nov 25, 2014 10:33 pm
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

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 12:11 am
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.

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 1:31 am
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

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 2:12 am
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.

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 4:21 am
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

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 9:50 am
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.

Re: Generating og:image tag

Posted: Wed Nov 26, 2014 11:17 am
by paulbaker
velden answered better (and quicker) than I could ;)

Re: [solved] Generating og:image tag

Posted: Wed Nov 26, 2014 6:04 pm
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

Re: [solved] Generating og:image tag

Posted: Wed Nov 26, 2014 6:08 pm
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'}