Normally I'm in the jQuery world, I develop a wep app using requirejs, backbone.js and jquery.
In order to broaden my horizon I also started using Dojo.
Before I started using Dojo, the statements that I was reading in several blogs about it in relation to jQuery were something like: "If you're making a normal website with some JS effects, you can use jQuery, but for the web app stuff you should use Dojo".
So, because of that, when I started with Dojo (1.7), I was eager to get to know its solutions for web app development.
The first thing that surprised me was that I did not find any base class for a mvc controller component. In backbone.js you have a view for that (many people say the backbone.js view is a controller), and this helps a lot.
Now, in my mvc controller component I want to render the view. I "load" the template by using an amd text plugin. For simple templating - I found out - you can use dojo.string.substitute. But I if you want to do something that's a little more complicated, you cannot use it.
I know that Rebecca Murphey, a well known javascript speaker, pulled Mustache.js into Dojo, when she started developing in this ecosystem.
But what Dojo native solutions do Dojo web application programmers use when they have to render a list with a dynamic number of lines and they want to achieve this by js templating?
In underscore templating. When you want to do this, you write something like the following in the template:
<div><%= lang_test %></div> <!-- static things -->
<table>
<% _.each(list, function(listitem){ %>
<tr>
<td><%= listitem.get('attr1') %></td>
<td><%= listitem.get('attr2') %></td>
</tr>
<% }); %>
</table>
Thanks alot
Wolfgang
Update:
Thank you, mkriheli, for your answer. I also stumbled over dojox.dtl!
I think I will use this.
You mentioned your preferred way to handle this are templated widgets. That's very interesting thing, WIDGETS AS PAGE CONTROLLERS WITH TEMPLATING!
1) My first javascript web 2.0 MVC page controller was a big custom jQuery UI widget. I heard that the jQuery UI team is planning to integrate templating into their widgets. I turned away from it after migrating to jquery with backbone.js.
2) As far as I know and understand, Justin Meyer from JavascriptMVC took the jQuery UI widget factory part (base part of jQuery UI widgets) and uses it in his framework as page controller.
3) Mark Wubben talked at a Dojo Conf about templating: He said:
This leads to a new and interesting approach for writing Dojo widgets. They can become much more like controllers: handling DOM events, implementing application logic and updating a model. The view will automatically reflect the changes.
For simple things you can use dojox.dtl.
My preference is creating a Templated Widget, see also the tutorial for Creating a custom widget.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With