Here's an example of a tag that I use on one of my sites to enable sharing on Facebook:
Code:
<p OnClick="JavaScript:window.open('http://www.facebook.com/sharer.php?u=http://www.yoursite.com<?UMBRACO_MACRO macroAlias="GetNiceLink"></?UMBRACO_MACRO>&t=<?UMBRACO_GETITEM field="pageName"/>','ShareOnFacebook',
'left=50,top=50,width=626,height=436,location=0,status=0,menubar=0,toolbar=0,resizable=1');" style="color: #bf1562; cursor: pointer; text-decoration: underline;">Share this recipe on Facebook</p>
In the example above I have styled the p-tag to act like an a-tag for some reason. In most cases you'd want to use a regular a-tag though.
If you want to see this snippet in action, check out:
http://www.lattehemma.se/recepten/gott-till/kakor-tartor-och-bakelser(click on any one of the recipes and scroll down on the page until you find the sentence "Dela med dig av detta recept på Facebook". It means "Share this recipe on Facebook" (in Swedish).
The macro that is embedded in this tag (GetNiceLink) corresponds to an XSLT-script that looks like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="sourceUrl" select="/macro/sourceUrl"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$sourceUrl != ''">
<xsl:value-of select="umbraco.library:NiceUrl($sourceUrl)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
It's a quite simple: either it takes a macro parameter in form of a page ID (sourceUrl) and converts that into a readable URL, or it takes the ID of the current page and does the same thing with that.
One thing that I haven't been able to figure out is how to make the Facebook sharing function pick the recipe image instead of the page head image. What it does now is that it simply picks the first image that it finds on the page so I guess one way of accomplishing that would be to alter the CSS and make the recipe image appear first in the HTML-code. That can be somewhat tricky though...
/Thomas K
Web Developer at Kärnhuset -
http://www.karnhuset.net - Stockholm, Sweden