<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>once upon my code &#187; plugin</title>
	<atom:link href="http://aefxx.com/tag/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://aefxx.com</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 18:40:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQote &#8211; client-side templating</title>
		<link>http://aefxx.com/jquery-plugins/jqote/</link>
		<comments>http://aefxx.com/jquery-plugins/jqote/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 17:52:10 +0000</pubDate>
		<dc:creator>aefxx</dc:creator>
				<category><![CDATA[jQuery plugins]]></category>
		<category><![CDATA[jQote]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://onceupon.com/?p=47</guid>
		<description><![CDATA[PLEASE NOTE:
jQote2 has been released. Please consider upgrading now!!! Click here for a quick summary of what&#8217;s new and what&#8217;s changed.
jQote (pronounced like Star Trek&#8217;s Chakotey) is basically a rewrite of John Resig&#8217;s awesome JavaScript Micro-Templating utility. I took his code and ported it to jQuery, overhauled the parsing / conversion part and extended it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<h3 class="pink">PLEASE NOTE:</h3>
<p class="pink"><strong>jQote2</strong> has been released. Please consider upgrading now!!! <a href="http://aefxx.com/jquery-plugins/jqote2/">Click here</a> for a quick summary of what&#8217;s new and what&#8217;s changed.</p>
<p>jQote (pronounced like Star Trek&#8217;s Chakotey) is basically a rewrite of <strong>John Resig&#8217;s</strong> awesome <a href="http://ejohn.org/blog/javascript-micro-templating/">JavaScript Micro-Templating</a> utility. I took his code and ported it to <a href="http://www.jquery.com/">jQuery</a>, overhauled the parsing / conversion part and extended it&#8217;s functionality to minimize everyone&#8217;s coding efforts.</p>
<p><span id="more-47"></span></p>
<p>See the <a href="api/jqote-reference/">jQote API reference</a>.</p>
<p><strong>PLEASE NOTE:</strong><br />
Version 1.1.0 now gives you the <strong>possibility of changing the tag character</strong> to something else than <% and %>. Please referr to the <a href="api/jqote-reference/">jQote API reference</a> to see how to do it.</p>
<p>So, let&#8217;s get started writing down a basic template:</p>
<pre class="code"><span class="blue">&lt;script type="text/html" id="template">
&lt;![CDATA[</span>
    &lt;p class="greetings"&gt;
        Hello <span class="pink">&lt;%= this.name %&gt;</span>, how are you doing?
        May I offer you
        <span class="pink">&lt;% this.is_starving() ? %&gt;</span>
            some tasty peasant?
        <span class="pink">&lt;% : %&gt;</span>
            a refreshing Singha?
        <span class="pink">&lt;% ; %&gt;</span>
    &lt;/p&gt;
<span class="blue">]]&gt;
&lt;/script></span></pre>
<p></p>
<p>This well-mannered code snippet &#8211; though it may not seem like much &#8211; shows some very special markup, namely <code class="pink">&lt;%= expression %></code> and <code class="pink">&lt;% statement %></code>, respectively (please notice the extra &#8216;=&#8217; sign on the first one).</p>
<p>As you may have guessed already, the code in-between these tags is mere JavaScript. To simplify things you should use the <code class="pink"><%= %></code> tag whenever you want to directly echo a variable&#8217;s value (you may as well call a function or use any other expression, as long as it returns a string).</p>
<p>Pretty self-explanatory so far, hu? But what&#8217;s with all that <code class="blue">&lt;script type="text/html"></code> and <code class="blue">&lt;![CDATA[ ... ]]&gt;</code> shmoo, you ask? Well let&#8217;s cite <strong>John Resig</strong> here:<br />
<cite>&#8220;Embedding scripts in your page that have a unknown content-type (such is the case here &#8211; the browser doesn&#8217;t know how to execute a text/html script) are simply ignored by the browser &#8211; and by search engines and screenreaders. It&#8217;s a perfect cloaking device for sneaking templates into your page. [...]&#8220;</cite></p>
<p>Good news, that is we will be able to put our template code right into our HMTL source files and it won&#8217;t show up anywhere but in the sources (btw. thanks to the usage of CDATA it&#8217;s perfectly valid markup).</p>
<p>Now for the final part of our little example we&#8217;ll need some basic scripting to induce the conversion:</p>
<pre class="code">
&lt;script type="text/javascript">
    var obj= {
        name: 'Jabberwocky',
        is_starving: function() {
            return Math.random() > 0.5;
        }
    };
    <span class="pink">$('#template').jqote(obj)</span>.appendTo($('body'));
&lt;/script></pre>
<p></p>
<p>That&#8217;s it, there&#8217;s nothing more to it than calling jQote on our template and providing it with some data object to get things started. jQote really is fun to use and cuts down on the time spent trying to inject arbitrary data into your sites. You&#8217;ll learn to love it pretty fast, I promise! Give it a try.</p>
<p>One final word: I&#8217;d like to thank <strong>John Resig</strong> for bringing this up. You rock, dude.</p>
]]></content:encoded>
			<wfw:commentRss>http://aefxx.com/jquery-plugins/jqote/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

