1

I have a share to Facebook button on a page that displays obituaries.

This site is coded in ColdFusion. What I am trying to do is pass the obituarietitle variable to the meta tag og:description like so:

<meta property="og:description" content="#obituarietitle#">

Through using the https://developers.facebook.com/tools/debug/og/object/ everything is showing up except the description which would be the name of the person who has passed.

The "share" shows #obituarietitle# the variable.I have tried cfoutput tags, cfsets, ect.

I am not seasoned with ColdFusion or og:, I don't know if this is possible.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
Pnet
  • 11
  • 1
  • 1
    If surrounding the variable in a `cfoutput` doesn't work, then either you don't have ColdFusion installed, or the requested page the code is on isn't a `.cfm` page so CF isn't rendering it. – beloitdavisja Mar 09 '16 at 14:28

1 Answers1

3

You must be in a cfoutput region to write variable contents to the output HTML.

So this would work:

<cfoutput>
<meta property="og:description" content="#EncodeForHTMLAttribute(obituarietitle)#">
</cfoutput>

Note the EncodeForHTMLAttribute() - calling this function is necessary to ensure that the value will not break your markup if it contains HTML-specific characters.

It is also a security precaution that prevents HTML injection. Make sure you use this function on all variable values that you output.


Edit: EncodeForHTMLAttribute() is a cousin of the EncodeForHTML() function, member of a group of functions designed to format ColdFusion values in such a way that they are suitable to be used safely in various contexts.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • 1
    `HTMLEditFormat` is deprecated in ColdFusion 10, use `encodeForHTMLAttribute` instead – John Whish Mar 09 '16 at 15:00
  • @John Oh, nice to know! I have not looked at the docs for that function in a long time, the deprecation notice slipped under my radar. I'm a bit uncertain though what where the effective, practical difference between `HTMLEditFormat` and `EncodeForHTMLAttribute` is. The docs are not helpful, can you add any insight? – Tomalak Mar 09 '16 at 15:30
  • For the difference between the two, see: http://stackoverflow.com/questions/10597073/encodeforhtml-vs-htmleditformat – James A Mohler Mar 09 '16 at 15:38
  • I tried It broke my site, here is the error: An error occurred at #DateFormat( Now(), "mmm d, yyyy" )# at #TimeFormat( Now(), "hh:mm TT" )# Error CGI REQUEST FORM URL SESSION mail sent mail not sent My file does end in .cfm - it is however a template file so .dwt.cfm where the meta tags are located-- not sure if that is an issue?? – Pnet Mar 09 '16 at 16:16
  • This looks like a new question. You should ask a new question with the revised code – James A Mohler Mar 09 '16 at 16:45