Connexions Course

by dandiebolt

HTML

<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<link rel="stylesheet" href="http://cnx.org/extjs/resources/css/ext-all.css">
<link rel="stylesheet" href="http://cnx.org/cnx-styles/newlook/document.css">
<link rel="stylesheet" href="http://cnx.org/cnx-styles/newlook/print.css">
<script id="template1" type="text/x-jquery-tmpl">

   <h1>${metadata.title}</h1>
    This is version ${metadata.version} of course <b>${metadata["content-id"]}</b> which can be found at the following url: <br/><br/><a href="${metadata['content-url']}" target="_blank">${metadata['content-url']}</a>
    
    <br/>
    <h1>Author Information:</h1>
    <b>userid:</b> ${metadata.actors.person.userid}<br/>
    <b>first name:</b> ${metadata.actors.person.firstname}<br/>
    <b>last name:</b> ${metadata.actors.person.surname}<br/>
    <b>email:</b> ${metadata.actors.person.email}<br/>
    <hr/>
    <h2>Sections</h2>
    
    {{each(index, section) content.section}} 

        {{each(key, item) section}}
            ${index}, ${key}<br/>
            {{tmpl ${"tt_" + ${key}} }}
        {{/each}}
 
    {{/each}}
    <!--
    <ul>
    {{each(i, section) content.section}}
        <li>
            <div>
                <h3>${i + 1}: ${title}.</h3>
                ID: ${para.id}<br/>
                Caption: ${para.caption}<br/>
                Content: ${para.content}<br/>
            </div>
         </li>
    {{/each}}
    </ul>
   -->
</script>

<script id="tt_id" type="text/x-jquery-tmpl">
    --- tt_id<br/>
</script>

<script id="tt_title" type="text/x-jquery-tmpl">
    --- tt_title<br/>
</script>

<script id="tt_para" type="text/x-jquery-tmpl">
    --- tt_para<br/>
</script>

<script id="tt_code" type="text/x-jquery-tmpl">
    --- tt_code<br/>
</script>

<script id="tt_list" type="text/x-jquery-tmpl">
    --- tt_list<br/>
</script>

<div id="info1"></div>

CSS

ul {
    list-style-type: none;
}

JavaScript

// YQL Query
// SELECT * 
// FROM XML
// WHERE url="http://cnx.org/content/m33979/latest/source"

// YQL Console Permalink
// http://developer.yahoo.com/yql/console/?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fcnx.org%2Fcontent%2Fm33979%2Flatest%2Fsource'&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

// YQL Query (JSON Response)
// http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fcnx.org%2Fcontent%2Fm33979%2Flatest%2Fsource'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?

var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fcnx.org%2Fcontent%2Fm33979%2Flatest%2Fsource'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?";

$.ajax({
    url: url,
    dataType: 'jsonp',
    success: function(data) {
        var document = data.query.results.document;
        $("#template1").tmpl(document).appendTo("#info1");
    }
});