Image Metadata content is not showing

Darpan Patel asked on October 26, 2017 07:54

step 1) first of all I have created page type, Fieldname: FbImageMetadata datatype: Attachment

step 2) upload image

step 3) below code put in master page tab of home page. <meta property="og:image" content="{% image = CurrentDocument.AllAttachments.Where("AttachmentGUID = '778e6f07-fd4e-44f3-ba25-28ec5a6e28b1'").TopN(1).FirstItem; return GetAbsoluteURL("~/getattachment/778e6f07-fd4e-44f3-ba25-28ec5a6e28b1/test) #%}">

still "og:image" content is blank.

Please give any suggestion

Correct Answer

David te Kloese answered on October 26, 2017 13:57

Well i'm not sure about performance but you can do something like:

{% foreach (doc in Documents.ClassNames("CMS.FBimageMetadata")) {
"<meta property='og:image' content='http://goodstart.org.au/getattachment/" + doc.AllAttachments.FirstItem.AttachmentGUID + "/attachment.aspx'" + "/>";
} |(identity)GlobalAdministrator%}

I'm selecting the first attachment for the found page. You might want to loop and/or do some null/empty checking! As well as doing some caching.

Just a tip: don't use the CMS prefix on your custom page types.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on October 26, 2017 08:18

First: why do you use hard-coded GUIDs? Shouldn't this be dynamic? What if the file is removed...

Secondly is this code directly on your template? Since Kentico macro's aren't resolved (by default) on templates. You either need extra code or preferably just a Web Part for macro's to be resolved.

0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 08:33 (last edited on October 26, 2017 08:38)

Hi David,

Thank you for the information,

First: why do you use hard-coded GUIDs? Shouldn't this be dynamic? What if the file is removed... yes dynamic

Secondly is this code directly on your template? Since Kentico macro's aren't resolved (by default) on templates. You either need extra code or preferably just a Web Part for macro's to be resolved

this code I have written in master page template. when I have used below macro code content should be blank.

<meta property="og:image" content="{%FbImageMetadata%}" />

or <meta property="og:image" content="/getattachment/{% FbImageMetadata %}/.aspx" />

and when I have put static meta tag on master page template

<meta property="og:image" content="http://euro-travel-example.com/thumbnail.jpg">

still content is blank.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 26, 2017 10:27 (last edited on December 10, 2019 02:31)

If you insert it into the head section:

Image Text

try using: <meta property="og:image" content="{% GetFileUrlByGUID(CurrentDocument.AllAttachments.FirstItem.AttachmentGUID, CurrentDocument.AllAttachments.FirstItem.AttachmentName , "") |(identity)GlobalAdministrator%}" />

my result seems to work:

<meta property="og:image" content="/getattachment/903ef7c4-e77d-47a7-b12e-33b63a16282d/myImage.jpg.aspx" />

you probably need more logic if you page contains more attachments. But this should get you started

1 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 11:06 (last edited on December 10, 2019 02:31)

Hi Devid,

using this code is working on different project and not my current project static data is also displayed blank but in another solution static data works , do you have any suggestion regarding this ? <meta property="og:image" content="{% GetFileUrlByGUID(CurrentDocument.AllAttachments.FirstItem.AttachmentGUID, CurrentDocument.AllAttachments.FirstItem.AttachmentName , "") |(identity)GlobalAdministrator%}" />

we have got random image of current document (CMS_Attachment) but I want to image that is uploaded on particulate page type in master page template like

**Pagetype name:FbImageGallery **

Fieldname: FbImageMetadata datatype: Attachment PFA images https://ibb.co/kSgyO6 https://ibb.co/mQwtqm

![Image Text](https://ibb.co/kSgyO6)

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 26, 2017 11:44

Are you sure you're looking at the correct master page?

If you're using the field I suggested, isn't the data overwritten by current template? Template has a HEAD section.

If nothing helps try creating an empty master page to see if static content is rendered correctly.

0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 11:53 (last edited on December 10, 2019 02:31)

ok I will check that but regarding this How will i get image that is uploaded on particulate page type? please correct below meta tag

 `<meta property="og:image" content="{% GetFileUrlByGUID(CurrentDocument.AllAttachments.FirstItem.AttachmentGUID, CurrentDocument.AllAttachments.FirstItem.AttachmentName , "") |(identity)GlobalAdministrator%}" />`
0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 13:37 (last edited on December 10, 2019 02:31)

I have stuck here

working

{% foreach (attachment in Documents[NodeALiasPath].AllAttachments) {
"<meta property='og:image' content='http://goodstart.org.au/getattachment/" + attachment.AttachmentGUID + "/attachment.aspx'" + "/>";
} |(identity)GlobalAdministrator%} 
0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 14:57

Thank you so much done

0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 26, 2017 15:57 (last edited on December 10, 2019 02:31)

Hi David ,

I want to write that code layout.master page

<meta property="og:title" content="{% CurrentPageInfo.DocumentName |(identity)GlobalAdministrator%}

this html code is not working in layout.master page but working in head html web part I think that is syntax issue.

PFA images
`https://ibb.co/ezUkLm`

https://ibb.co/ftsSY6

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on October 26, 2017 19:58

Macros are not supported in the layout like this. Once in the ASPX code, use the code behind and standard API methods for pages.

0 votesVote for this answer Mark as a Correct answer

Darpan Patel answered on October 27, 2017 06:11

Hi Juraj,

Thank you for information

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on October 30, 2017 09:49

Hi Darpan,

Since you were making use of Portal Engine you could have make use of this web part.

Facebook open graph webpart

Thanks, Chetan

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.