# inputEx - YQL-trimpath-page

back to the inputEx library

## Introduction

This utility makes it easy to use the Yahoo! Query Language (YQL) from web pages.

YQL Execute gives the ability to execute JavaScript on Yahoo!'s platform, with a very powerful API to query the web.

We combine this new backend with client-side templating using Trimpath templates.

To use this utility, you will need to be familiar with the trimpath templates syntax and the yql api.

Furthermore, we provide an editor, based on YUI Grids CSS builder, to create pages from YQL code + trimpath templates.

## Demo

Here is a custom example: example using a flickr query, YQL logging and diagnostics, and custom javascript handler.

## Usage

Add YQL Execute code in script tags with a type set to "text/yql".

Add them at the end of your body tag ; This code will run on the Yahoo! YQL platform.

<script type="text/yql"> y.log("Hello World"); var q = "select * from flickr.photos.search where text=\"juggler\""; var query = y.query(q); var json = y.xmlToJson(query.results); y.log("Everything's fine"); response.object = json; </script>

Add templates in your code in script tags with a type set to "text/trimpath".

The result of this template will be inserted where the script tag is in the dom.

The src attribute must be set to the index of the YQL query ("#0" for the first query).

In your templates, the results are accessible through the "query" object.

<script type="text/trimpath" src="#0"> {for p in query.results.results.photo} <a href="http://farm${p.farm}.static.flickr.com/${p.server}/${p.id}_${p.secret}_b.jpg"> <img src="http://farm${p.farm}.static.flickr.com/${p.server}/${p.id}_${p.secret}_s.jpg"> </a> {/for} </script>

You can add multiple template script tags at various places in your dom for the same YQL query.

You will also need to install the javascript dependencies : YUI utilities and json, the trimpath-template library, 3 files from inputEx + a line to run the trimpath page utility.

<script type="text/javascript" src="../lib/yui/utilities/utilities.js"></script> <script type="text/javascript" src="../lib/yui/json/json-min.js"></script> <script type="text/javascript" src="../lib/trimpath-template-1.0.38.js"></script> <script type="text/javascript" src="../js/inputex.js"></script> <script type="text/javascript" src="../js/rpc/yql.js"></script> <script type="text/javascript">YAHOO.util.Event.onDOMReady(inputEx.YQL.initTrimpathPage, inputEx.YQL, true);</script>

You can also add custom javascript handlers for each query (You may want to use widgets for advanced visualization)

YAHOO.util.Event.onDOMReady(function () { // This is an example of an additionnal callback, to display a JsonTreeInspector widget from the yql response var callback0 = function(results) { new inputEx.widget.JsonTreeInspector('treeContainer', {query: results.query}); }; // Call the yql-trimpath-page utility (with a list of callbacks for each "text/yql" script tag) inputEx.YQL.initTrimpathPage([[callback0]]); });

## Behind the scene

We generate a YQL XML through: http://javascript.neyric.com/yql/. (like this one)

Then, we build a YQL query, to use this XML file : (actually the xml file is requested by YQL servers)

use 'http://javascript.neyric.com/yql/js.php?code=y.log(%22test%22)' as t; select * from t;

We finally get the results of this query through JSON-P.

Enjoy !