<xmod:JsonFeed>

The JsonFeed tag, first introduced in version 4.3, is used to easily generate JSON output from your data. JSON is the lingua franca of client-server communication these days and many Javascript and jQuery plugins natively consume it. You could create a JSON feed using the standard feed tag, but the JsonFeed tag saves you a lot of typing. There may still be times when you want to use special layouts or formatting in your feed that you'll want to use the Feed tag, but in most situations, the JsonFeed is all you need.

Creating A Feed

Creating a feed is a two-step process:

  1. Create your feed on the Manage Feeds page in the Control Panel. The Feed is very similar to XMod Pro's Template tag and is created in a similar fashion. You begin by clicking the "New Feed" button. On the dialog which pops-up, choose the type of feed you want to create, select a data source, and click the dialog's "New Feed" button to create it. From there, you can edit your feed in the editor.

    The JsonFeed tag is VERY simple. All you need to do is specify the <xmod:JsonFeed> tag and a <ListDataSource>. That's it. Seriously. XMod Pro will do the extra work of setting your content type to application/json, and formatting the data that comes from the ListDataSource so that the values are properly escaped and formatted for JSON. It will also take the column names from your ListDataSource and use those as the property names in your JSON object.

    For Example:

    <xmod:JsonFeed>
      <ListDataSource CommandText="SELECT FirstName, LastName FROM vw_Users" />
    </xmod:JsonFeed>

    XMod Pro will create a Javascript Array and add an object for each record returned. For the above, the returned result may look something like this:

    [ { "FirstName" : "John", "LastName" : "Smith"},
       { "FirstName" : "Suzy", "LastName", "Harris" },
       { "FirstName" : "Sinead", "Conner" } ]



  2. Call your feed. You can get an example of how to call your feed by clicking the "How To Call Your Feed" link on the Manage Feeds page. Basically, you link to it like you would any other page. You'll call XMod Pro's "Feed.aspx" page and pass it a few required parameters and any additional parameters your data source may need to retrieve the data.

    Use a URL in the form of:
    http://sitename/DesktopModules/XModPro/Feed.aspx?xfd=FeedName&pid=PortalId

    Where sitename is your site's domain, FeedName is the name of the feed as listed in the grid, and PortalId is the numeric ID of the portal for which the feed is created.

A Note About Security

It's important to note that feeds, by their nature, are typically intended to be public. No special security measures have been implemented for securing the feed. So you should be careful about what data you make available through a feed. One way you could make your feed more secure is by creating and passing a token to the feed. This token would then be checked by your data source (most likely a stored procedure) to determine its validity, returning the data only if it's valid.

     

Syntax

<xmod:feed
    Doctype="string"
    ContentType="string"
    ConnectionString="string"
    Filename="string"
    ViewRoles="role1,role2,role3">

    <ListDataSource CommandText="string"
        ConnectionString="string"/>

 

    <HeaderTemplate>...</HeaderTemplate>
    <ItemTemplate>...</ItemTemplate>
    <AlternatingItemTemplate>...</AlternatingItemTemplate>
    <SeparatorTemplate>...</SeparatorTemplate>

    <FooterTemplate>...</FooterTemplate>

</xmod:feed>

Remarks

Back to top

Example

<xmod:JsonFeed>
<ListDataSource CommandText="SELECT [AuthorId], [FirstName], [LastName], [GenreId] FROM Authors WHERE 
GenreId = @gid">
  <Parameter Name="gid" Value='[[Url:genre]]' DataType="Int32" DefaultValue="-1" />
</ListDataSource>
</xmod:JsonFeed>
Back to top