-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest for templating #20
Comments
Hey Rafael, have you seen branch 2.0 yet? You can use any template engine you want and you don't even have to specify in the options. Check it out here. I used Underscore initially because it is dead simple to use. Basically you pass the entire compiled object which later gets sent the data. I just have to add support for other libraries that don't make it so easy. When you set the options like this:
what basically happens inside the plugin is this (pseudo-code):
so in the above example this is essentially the sequence of events:
which is identical to Underscore's suggested usage:
All I have to do for the other libraries is account for their various jQuery: Hogan.js: etc... |
Hi, Terry! Yes, I've seen that code. I just think it woudn't good to DEPEND of any Twig has almost the same call as Underscore does (instance, pass an object Maybe you can use jQuery.tmpl as default - as you already have this []'s 2012/10/4 Terry Rosen [email protected]
|
Hi, nice plugin, thank you very much for the efforts you're doing to keep it up. ;$(function() {
// People
var name_source = [{
id : 102690,
first_name : "John",
second_name : "Doe",
birthdate : "03/07/1946",
type : "type1"
},
{
id : 104281,
first_name : "Jane",
second_name : "Doe",
birthdate : "04/09/1948",
type : "type2"
},
{
id : 103675,
first_name : "Baby",
second_name : "Doe",
birthdate : "26/11/1978",
type : "type3"
}];
// Typeahead
$('.autocomplete.name').typeahead({
source: name_source,
tmpl: _.template("<li id='<%= id %>' class='<%= type%>'><a href='#' title='<%= first_name %> <%= second_name %> - edit'><span class='name'><%= first_name%> <%= second_name %></span><span>Birthdate: <%= birthdate %></span></a></li>")
});
}); But on js console I just get: I'm not sure, seems that the "display" option must be specified, but it accepts just one item attribute (e.g. "first_name") and I'd like to show multiple attributes per item based on the custom template I created. |
I have successfully been able to pass in a compiled mustache template: $('#typeahead-search').typeahead({ this is using a compiled moustache template (in this case provided by ICanHaz.js - http://railsware.com/blog/2012/04/12/shared-mustache-templates-for-rails-3/) |
Hi,
I really liked your fork.
I read your idea for templating, and want to give you my two cents.
I wouldn't force the use of a template engine (I like Underscore.js, but I also like Twig.js).
Suggestion:
});
Then the render method could call any of externals template engines (underscore, twig) or a simple internal "templater" that just uses variable replacement with a pattern or regex.
[]'s
Rafael Goulart from Brazil
The text was updated successfully, but these errors were encountered: