Server side compiled templates #133

Closed
jstar88 opened this Issue Feb 25, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@jstar88

jstar88 commented Feb 25, 2013

Hello, i tryed to compile this template from an java server:

  <p><font color=red>Your text here: {{text}}</font></p>

and the result is :

 function(c,p,i){var _=this;_.b(i=i||"");_.b("<p><font color=red>Your text here: ");_.b(_.v(_.f("text",c,p,0)));_.b("</font></p>");return _.fl();;}

but firebug tell me this error inside hogan.js:

 this.r is not a function 

 // render internal -- a hook for overrides that catches partials too
 ri: function (context, partials, indent) {
 return this.r(context, partials, indent);
 }, 

ps : on client i run this code

$(document).ready(function() {

        $.ajax({
            url : '@routes.StaticFilesController.getTemplate("game/index")',
            dataType : 'text',
            success : function (data,stato) {
                template = new Hogan.Template(data);
                data = {
                        text: 'Hello World'
                      };

                $("#content").append(template.render(data));
            },
            error : function (richiesta,stato,errori) {
                alert("E' evvenuto un errore. Il stato della chiamata: "+stato +":"+errori);
            }
        });
});

regards

@benrhughes

This comment has been minimized.

Show comment Hide comment
@benrhughes

benrhughes Mar 10, 2013

I just figured this out the hard way for myself (this helped a lot: https://gist.github.com/kasperp/1536490).

The compiled string you get isn't enough. You need to create a new Hogan.Template() with it, eg

var hello_c = function(c,p,i){....};
var hello = new Hogan.Template( hello_c, "hello" );

You can then use hello as a template.

I haven't found much doco at all on pre-compiling templates unfortunately. The solution I just threw together is here: https://gist.github.com/benrhughes/5128490

I just figured this out the hard way for myself (this helped a lot: https://gist.github.com/kasperp/1536490).

The compiled string you get isn't enough. You need to create a new Hogan.Template() with it, eg

var hello_c = function(c,p,i){....};
var hello = new Hogan.Template( hello_c, "hello" );

You can then use hello as a template.

I haven't found much doco at all on pre-compiling templates unfortunately. The solution I just threw together is here: https://gist.github.com/benrhughes/5128490

@sayrer sayrer closed this Aug 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment