Reusable Content and Embedded Gadgets

Easily embed web-gadget code snippets and frequently reused content in umbraco cms

This package for umbraco4 creates an easy to use setup of doctypes, macros, and xslt to quickly store snippets--such as youTube links or frequently reused bits of content--to be inserted into pages or templates via macros.

The Reusable Content Package for umbraco is my first to be made public.  It's based on forum posts and experimentation, but works and is fairly straightforward.

Endlessly Hilarious Video

Working on a Halloween Costume of the guy, but Stuck on the Shirt.

Once installed through the Packages branch in the Developer section of the umbraco GUI, three new DocTypes, two Macros, and one XSLT file will be added to your umbraco site.

The doctypes include a folder to hold reusable content, and one of two ways of entering the content snippet--via multiline textbox for quick pasting with no tidying applied, or through a richtext editor for more refined bits of code or markup. Create a new content folder at the root level of your site, then add to it some items, and in those items store your snippets.  Then, when editing content in your main site-branch you can insert a macro to call up the snippet.

Another Sample Embedded Video

There are two macros included.  One requires you to know the id of the snippet node, which can be discerned by hovering and looking at the link.  The other uses the Content Picker to let you select the item from the content tree.

By default the macros don't render in the richtext editor, but you can enable that on their page in the Developer section.  It works for many typical examples--but not flash video, it doesn't look like.  I'd leave it off, personally.

Attempting to store code snippets in media items raises cross-site scripting warnings, so storing them as lookless (no template) content works well enough.

Both macros reference the same xslt file which looks up the node from the id value then displays the snippet unescaped.

If you copy and paste the xslt, you can make your own macros and doctypes fairly quickly--if you'd prefer not to use the package.

<?xml version="1.0" encoding="UTF-8"?>
<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="GadgetID" select="/macro/gadgetid"/>
<xsl:template match="/">
  <xsl:if test="$GadgetID != ''">
    <xsl:value-of select="umbraco.library:GetXmlNodeById($GadgetID)/data" disable-output-escaping="yes"/>
  </xsl:if>
</xsl:template>
</xsl:stylesheet>
Check XHTML  «  feebdack.com  Copyright ©  Xander Lih  2000-2009   »  Check CSS