| Page 1 of 2 | [ 11 posts ] | Go to page 1, 2 Next |
|
Hi everyone,
I can't get a simple handlebars example to work when I change the compatibility mode of IE to IE8 or IE7. it seems that the handlebars script tag 'text/x-handlebars-template' returns an empty string when Y.one('#list-template').get('text') is called. In IE9, it works fine. Am I doing something wrong? Thanks. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <script src="http://yui.yahooapis.com/3.5.0pre5/build/yui/yui-min.js" type="text/javascript"></script> <script type="text/javascript"> YUI().use('handlebars', 'node-base', function (Y) { // Extract the template string and compile it into a reusable function. var source = Y.one('#list-template').get('text'), template = Y.Handlebars.compile(source), html; // Render the template to HTML using the specified data. html = template({ items: [ {name: 'pie', url: 'http://pieisgood.org/'}, {name: 'mountain dew', url: 'http://www.mountaindew.com/'}, {name: 'kittens', url: 'http://www.flickr.com/search/?q=kittens'}, {name: 'rainbows', url: 'http://www.youtube.com/watch?v=OQSNhk5ICTI'} ] }); // Append the rendered template to the page. Y.one('body').append(html); }); </script> </head> <body> <script id="list-template" type="text/x-handlebars-template"> <p>YUI is brought to you by:</p> <ul> {{#items}} <li><a href="{{url}}">{{name}}</a></li> {{/items}} </ul> </script> </body> </html> |
|
So if I do
Code: document.getElementById("list-template").innerHTML Instead of use YUI to grab the contents of the template, then it works. I guess this might be a feature enhancement for the Y.Node module? |
Juan Ignacio DopazoYUI Contributor
|
Have you tried waiting for the domready event with Y.on('domready', fn)?
|
|
Hi Juan,
Thank you for your suggestion. It's exactly what I needed. |
|
Scratch that. I spoke too soon! I forgot to change the call from using document.getElementById() to Y.one().get('text').
Executing the logic within the 'domready' callback does not fix the issue. |
Juan Ignacio DopazoYUI Contributor
|
Ok, I looked up the code. node.get('text') uses textContent or innerText. I don't have IE8 around at the moment so I can't check, but it's possible IE < 9 doesn't have innerText for script tags. Have you tried node.getContent() or node.get('innerHTML')?
|
|
Nice! Thanks a bunch!
Using the .getHTML() or .get('innerHTML') works fine across the IE versions. Guess you are correct about IE7 and IE8 not supporting .get('text'). .getContent() is deprecated so I wont use that one. Thank you again! |
Juan Ignacio DopazoYUI Contributor
|
:O I didn't know that!
|
|
Oh I just double checked the API doc. In stage, it's for YUI 3.5 pre5 that it has been deprecated
|
MarcYUI Contributor
|
I have the same problem when I try to retrieve script content in a document fragment.
var script = content.all('script').toFrag().getHTML(); returns undefined. Hmm, var script = content.all('script').getHTML(); seems to work although it returns an array |
| Page 1 of 2 | [ 11 posts ] | Go to page 1, 2 Next |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group