Latest Headlines via JSON

JSON (and XML) Content ServicesJSON Content

dotCMS 1.9 allows dynamic content to be delivered via JSON or XML by just hitting a URL.  By passing a content query and some parameters, you can pull a feed of content from dotCMS and use it with Javascript/jQuery or integrate it with other systems. 

The simple example below is using jQuery to hit the /JSONContent url specified, getting a list of the latest 10 news items ordered by publish date descending and then displaying them in on the page. 

JSON/XML Content Engine : /JSONContent
JSON news in debug mode : /JSONContent/?type=json&q=%2BstructureName%3ANewsItem+%2B%28conhost%3A48190c8c-42c4-46af-8d1a-0cd5db894797+conhost%3Abee14013-9a29-4187-9985-afaa9522e01d%29%26orderBy%3DNewsItem.publishDate&limit=10

Code to make this happen

#set($url = "/JSONContent/?type=json&q=%2BstructureName%3ANewsItem+%2B%28conhost%3A48190c8c-42c4-46af-8d1a-0cd5db894797+conhost%3Abee14013-9a29-4187-9985-afaa9522e01d%29%26orderBy%3DNewsItem.publishDate&limit=10")

<h2>Latest Headlines via JSON</h2>
<div id="headlines">

      var jQueryVelocity = jQuery.noConflict();

    jQueryVelocity.getJSON("$url",  function(data){
    jQueryVelocity.each(data.contentlets, function(i,item){
      if(item.urlTitle && item.headline ){
        jQueryVelocity("<div style='border-top:1px solid silver;padding:10px'/>").attr("innerHTML", "<a href='/news/" + item.urlTitle +"'>"+ item.headline +"</a>").appendTo("#headlines");
© 2017 dotCMS Inc. All rights reserved.