oEmbed and JSON Plugins Available

Published on September 14, 2010 by in Macros, Plugins, Viewtools


Today, I am announcing the release of two new plugins for dotCMS, available now. The reason I am announcing them together is because the macro relies on the viewtool, but the viewtool has applications beyond the macro, so I didn’t feel that it was right to make it one big plugin. Also, the viewtool is only necessary in dotCMS 1.9 or lower. It is built in to dotCMS 1.9.1.

The viewtool is a fairly simple, straightforward implementation of the JSON Java class. Like the XML viewtool, it allows you to request JSON data via a URI, bring it into Velocity, and use it to manipulate information on a page. In the case of these plugins, the oEmbed macro uses it to request the JSON representation of an oEmbed object, and fetch out the values needed to display the content. As noted, this viewtool has been included in the trunk code for the upcoming 1.9.1 dotCMS update, so this plugin is only necessary if you are on 1.7 or the base 1.9 install. The viewtool plugin is mapped to the same key, so if you install it on a 1.7/9 system and then upgrade to 1.9.1, just remove the plugin and nothing should break. Beyond that, you can use it to process any other JSON data sources that you need.

[ Download JSONTool Viewtool Plugin (v1.100914) ]

#set($jsonData = $json.fetch('http://oohembed.com/oohembed/?url=http%3A//www.amazon.com/Myths-Innovation-Scott-Berkun/dp/0596527055/'))

#set($mymap = $contents.getEmptyMap())
#set($dummy = $mymap.put('one','value 1'))
#set($dummy = $mymap.put('two','value 2'))
#set($dummy = $mymap.put('three','value 3'))
#set($myjson = $json.generate($mymap))
<p>The value of key 'one' is $!{myjson.get('one')}</p>
The Myths of Innovation

{"two":"value 2","one":"value 1","three":"value 3"}
The value of key 'one' is value 1

The second plugin is a macro that allows you to add oEmbed sources of data to your site, and it requires the JSONTool viewtool, either as a plugin or in 1.9.1, because it uses the oohEmbed API to set up the embed code which responds with JSON data. Using an oEmbed compatible URI, the #oembed() macro will fetch the applicable code and allow you to embed it on your page. This is great for a simple way of embedding YouTube or Vimeo videos, or images from Flickr, as well as many other services. The oohEmbed website lists all of the sites they currently support.

[ Download oEmbed Macro Plugin (v1.100914) ] (requires the JSON viewtool!)

Macro Syntax:



  • sourceURI:
    This is the only require parameter and should represent a well-formed oEmbed compatible URI (see the respective web site for proper URI formatting).
  • oembedH:
    Define the height of the oEmbed object (optional, velocity variable). Default: JSON oEmbed height value
  • oembedW:
    Define the width of the oEmbed object (optional, velocity variable). Default: JSON oEmbed width value
  • oembedClass:
    Provide a specific class name for the embed div wrapper (optional, velocity variable). Default: ‘oembedMedia’
  • useThumbnail:
    Boolean value, allows you to display the thumbnail with a link to the resource url. Only works with ‘photo’ type oEmbed data (optional, velocity variable). Default: false



Advanced Example:

#set($oembedH     = 267)
#set($oembedW     = 400)
#set($oembedClass = 'oembedFlickrPhoto')

One Response to “oEmbed and JSON Plugins Available”

  1. Moon says:

    Thank you for the great tool. I have a question.

    How do I access json data when the data have multiple rows? for example,


Leave a Reply