BorisMoore / jquery-tmpl

The original official jQuery Templates plugin. This project was maintained by the jQuery team as an official jQuery plugin. It is no longer in active development, and has been superseded by JsRender.
3.23k stars 1.01k forks source link

bug : tmplItem object not attached if no space after tag name #92

Open lgersman opened 13 years ago

lgersman commented 13 years ago

an example says more than 1000 words :

<script id="foo" type="text/x-jquery-tmpl"> 
    <textarea{{tmpl '#bar'}}>hello world</textarea>
</script>
<script id="bar" type="text/x-jquery-tmpl">
    halali
</script>
<script type="text/javascript" >
$( window).ready( function() {
    $("#foo").tmpl({}).appendTo( 'body'); 
});
</script>

the example source above will NOT attach the tmplItem to the create TEXTAREA element. when i keep a space after <textarea it will work.

sorry for the (semantically) senseless example :-( anyway, it shows the problem.

as far as i know, this is a result of a more-or-less bad expressed regex in function function build( tmplItem, nested, content ) where the element tag name wil be replaced by its name PLUS the tmpl key so that the tmplitem can later be attached to the dom element.

hope this helps,

lars gersmann

ghost commented 13 years ago

Hey lars,

Not sure if I misunderstand the bug but here is what I see when running your code:

You create a textarea with the default value 'hello world' in the foo template and that is added to the body of the document, so far so good. Now, this is where I get a little lost. Do you want to add halali to the text area or as an attribute of the textarea tag.

Currently it generates the following, which is exactly what your template tells it to do:

<textareahalali>hello world</textareahalali>

If the intention was to add it as an attribute then your code needs to change to the following:

<textarea {{tmpl '#bar'}}>hello world</textarea>

And if you wanted to add it into the textare then it would have to be:

<textarea>hello world {{tmpl '#bar'}}</textarea>

As I mentioned, I might be misunderstanding your problem but this is what I see when running the code you provided.

Schalk

lgersman commented 13 years ago

Hello,

as i said in the initial statement - my example is worse :-)

i use the tmpl plugin to generate NON HTML text (sounds strange but works fine when the template gets "prepared for the tmpl plugin" :-).

in my templates its often the case the a word (\w) is immediately followed by a tmpl expresssion. and in this case the mentioned regex function build( tmplItem, nested, content) doesnt match for template content like foo{{tmpl '#bar'}} the result is that the tmplItem will not be appended to the tmplitem tree.

kind regards,

lars

rdworth commented 13 years ago

Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.