Page 1 of 1

SOLVED: News Module: Show Field Definition on a Template

Posted: Wed Oct 02, 2013 7:03 pm
by joecannes
Hi,

In the news module, I created a field module for the user to assign an image to a news item. In my summary and detail template, this is how I call it:

Code: Select all

{if !empty($entry->summaryimage)}
                                    <img src="{$entry->file_location}/{$entry->summaryimage}" alt="" />
                                    {else}
                                    <img src="uploads/images/news-default-image.gif"  alt=""/>
                                    {/if}
NOW, I want to add that image on my news template. I tried this:

Code: Select all

{if !empty($entry->summaryimage)}
<meta property="og:image" content="{root_url}/{$entry->summaryimage}" />
{/if}
But it is not appearing. How can I show a news field definition on a template?


Reason I am calling that image on my template, is so that image can be added to the facebook META data, and that image will be picked up if a user shares that page. The Facebook META data has to sit in the HEAD of the page, not in the BODY of the page.

Thanks for any help!

Joe C.

Re: News Module: Show Field Definition on a Template

Posted: Wed Oct 02, 2013 7:04 pm
by joecannes
One thing, when I created the field definition, I set the visibility to PUBLIC as well

Re: SOLVED: News Module: Show Field Definition on a Template

Posted: Wed Oct 02, 2013 8:10 pm
by joecannes
Hi all,

I solved it, here is what I did:

1. In my detail template, I setup a new variable for the image field definition my facebook image:

Code: Select all

{assign var='fb_post_image_location'  value=$entry->file_location}
{assign var='fb_post_image'  value=$entry->summaryimage}
Then on my template, I wrote this in the HEAD tag:

Code: Select all

{if isset($fb_post_image)}
<meta property="og:image" content="{$fb_post_image_location}/{$fb_post_image}" />
  {/if}
So if the user uploads an image, the META data will then appear in the HEAD tag.

I tried it out, and it works fine, even through Facebook Linter, I was getting the right variables I wanted.

Hope this helps someone out there!

Joe C.

P.S. I also tried appending it through jquery and javascript, and it was getting picked up, but Facebook was not reading it. if anyone wants to see what I did, it was this in my news detail template:

Code: Select all

{literal}
<__script__>

$(document).ready(function(){
    //set facebook Open Graph description
    $('head').append('<meta property="og:image" content="{/literal}{$entry->file_location}/{$entry->summaryimage}{literal}" />');
    
    
});
</__script>{/literal}