Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save critmcdonald/9715299 to your computer and use it in GitHub Desktop.
Save critmcdonald/9715299 to your computer and use it in GitHub Desktop.
Passing Caspio variable for Facebook sharing
// First, in my Caspio search result, I don't include the
// detail page in the report, but instead create an HTML field that links
// to the report and passes two fields: the VenueID, which is used to pull
// the right record, and the SVenue, which is the name of the venue that
// I need for sharing.
<a href="venue.php?VenueID=[@field:VenueID]&Venue=[@field:SVenue]">[@field:SVenue]</a><br />
// This gives me a url like this:
http://projects.statesman.com/happy-hours/venue.php?VenueID=3&Venue=Aussie%27s
// Here is the PHP code. It gets the URL, parses the Query part, breaks it into parts
// so I can get the last part, search and replaces things like commas accents
// and sets it as the variable to use later.
<?php
$url = $_SERVER['REQUEST_URI'];
$path = parse_url($url, PHP_URL_QUERY);
$pathFragments = explode('=', $path);
$venue = end($pathFragments);
$search = array("%20", "%27","%C3%A9");
$replace = array(" ", "'","&#233;");
$venue = str_replace($search, $replace, $venue);
?>
// And with the $venue variable set, I use it to write the metatag
<meta property="og:title" content="Happy hour specials at <?php echo $venue; ?>"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment