<?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>.NET Tips and Tricks &#187; dom template</title>
	<atom:link href="http://kossovsky.net/index.php/tag/dom-template/feed/" rel="self" type="application/rss+xml" />
	<link>http://kossovsky.net</link>
	<description>C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks</description>
	<lastBuildDate>Sat, 25 Dec 2010 08:32:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>jTemplates &#8211; jQuery Template Engine</title>
		<link>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/</link>
		<comments>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 22:46:51 +0000</pubDate>
		<dc:creator>Xander</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[c-sharp]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dom template]]></category>
		<category><![CDATA[dynamic template]]></category>
		<category><![CDATA[endless event]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[event handlers]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[javascript library]]></category>
		<category><![CDATA[javascript templates]]></category>
		<category><![CDATA[jquery templates]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[js template]]></category>
		<category><![CDATA[net c#]]></category>
		<category><![CDATA[rapid web development]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[server side code]]></category>
		<category><![CDATA[side requests]]></category>
		<category><![CDATA[support parameters]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[template engine]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[time manipulation]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[usable features]]></category>
		<category><![CDATA[web template]]></category>

		<guid isPermaLink="false">http://kossovsky.net/?p=789</guid>
		<description><![CDATA[jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.
The syntax is very simple and  intuitive. It's support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (12 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />]]></description>
			<content:encoded><![CDATA[<p>About a year ago i had to architucture some web application with a very rich client side UI.</p>
<p>ASP.NET was an easy choise for a server side code, but what about client side ?<br />
The heavy viewstate, endless event handlers and infinity number of server side requests just to make the GUI  friendly &#8211; well, it just didn&#8217;t sound as a proper way to do it.</p>
<p><span id="more-789"></span>So, what do we have ?<br />
.NET as a server side platform, but despite  all it&#8217;s powerful abilities it has nothing to do with client side. At the end of the day all those fancy control are just HTML and JavaScript.</p>
<p> JavaScript is still the engine that runs at the client side and it&#8217;s great, but we all know how many lines of code we have to write and time to spend to make it fast, modular and cross browser.</p>
<p><a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a> &#8211; it&#8217;s a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.</p>
<p>Indeed, we can do a many things with jQuery and it realy simplify the coding, but what if we have to build a product list with complicated HMTL, complex logic and real time manipulation ?</p>
<p>As i mentioned before, ASP.NET and UpdatePanels are just to heavy and JavaScript is to long.</p>
<p>So, i did some research and find a couple of JavaScript Template Engines.<br />
The first one i bumped in was <a href="http://plugins.jquery.com/project/jsrepeater" target="_blank">jsRepeater</a>. At first it seemed like a great solution but after a few tests i found all kinds of bugs related to the syntax conflicts with HTML and JavaScript.</p>
<p>After a few days of googling, tests and googling again i found the one and only &#8211;  <a title="jTemplates" href="http://jtemplates.tpython.com/" target="_blank">jTemplates</a>.<br />
jTemplates is a template engine for JavaScript, wich is wraped in a jQuery Plugin.<br />
The syntax is very simple and  intuitive. It&#8217;s support parameters, includes, if/else, loops, JavaScript functions and many other nice and usable  features.</p>
<p>Let&#8217;s say we want to list all our products. What we have to do is to write the template (HTML), pass the data and we have a product list.</p>
<p>
<div><span style="color: #0000ff;">{#foreach $T.Product as P}</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span> <span style="color: #008000;">style</span>=&#8221;float:left;width:150px;height:150px&#8221;<span style="color: #0000ff;">&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span><strong>{$T.P.Title}</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">img</span> <span style="color: #008000;">src</span>=&#8221;<strong>{$T.P.Url}</strong>&#8221; <span style="color: #008000;">alt</span>=&#8221;<strong>{$T.P.Title}</strong>&#8221; style=&#8221;width:10px;height:10px&#8221; <span style="color: #0000ff;">/&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;hr /&gt;</span></div>
<div style="padding-left: 60px;"><span style="color: #0000ff;">&lt;</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span>Price : <strong>{$T.P.Price}$</strong><span style="color: #0000ff;">&lt;/div&gt;</span></div>
<div style="padding-left: 30px;"><span style="color: #0000ff;">&lt;/</span><span style="color: #0000ff;">div</span><span style="color: #0000ff;">&gt;</span></div>
<div><span style="color: #0000ff;">{#/for}</span></div>
</p>
<p>Look how easy this is. You just write HTML and werever you need to insert some data you put {$.T.P.ColumnName}.</p>
<p>So, how we use it ?<br />
Just add some textarea to your page, give it some id, set it&#8217;s display style to none and write your template inside.</p>
<pre class="html" name="code">
&lt;textarea cols="0" rows ="0" style="display:none;" id="ProductListTemplate"&gt;&lt;!--
{#foreach $T.Product as P}
	&lt;div style=”float:left;width:150px;height:150px”&gt;
		&lt;div>{$T.P.Title}&lt;/div&gt;
		&lt;img src=”{$T.P.Url}” alt=”{$T.P.Title}” style=”width:10px;height:10px” /&gt;
		&lt;hr /&gt;
		&lt;div>Price : {$T.P.Price}$&lt;/div&gt;
	&lt;/div&gt;
{#/for}
--&gt;&lt;/textarea&gt;
</pre>
<p>Add some empty container that will hold the result.</p>
<pre class="html" name="code">
&lt;div id="ProductListContainer"&gt;&lt;/div&gt;
</pre>
<p>Execute setTemplateElement and execute processTemplate while passing the data into it as a parameter</p>
<pre class="javascript" name="code">
$("#ProductListContainer").setTemplateElement("ProductListTemplate");
$("#ProductListContainer").processTemplate(data);
</pre>
<p>Easy, isn&#8217;t it ?<br />
I must say that the above example is a simple one, but I&#8217;ve been using jTemplates to create complicated lists, grids, trees, popups and even an image editing web application. Use it, I&#8217;m sure you will love it.</p>
<div style="margin-top:-15px;margin-bottom:15px;"><script type="text/javascript">
var dzone_url = 'http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/';
var dzone_style = '1';
</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>
<br /><div><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx.php?value=4.9" /></div><div>Rating: 4.9/<strong>5</strong> (12 votes cast)</div><br /><a target="_blank" href="http://www.gdstarrating.com/"><img src="http://kossovsky.net/wp-content/plugins/gd-star-rating/gfx/powered.png" border="0" width="80" height="15" /></a><br />
<p class="FacebookLikeButton"><fb:like href="http%3A%2F%2Fkossovsky.net%2Findex.php%2F2009%2F10%2Fjtemplates-jquery-template-engine%2F" layout="standard" show_faces="false" width="450" action="like" colorscheme="light"></fb:like></p>
]]></content:encoded>
			<wfw:commentRss>http://kossovsky.net/index.php/2009/10/jtemplates-jquery-template-engine/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

