[ 2 posts ]

Marc

YUI Contributor

  • Offline
  • Profile

Handlebars, partials and loader

Post Posted: Wed Jul 04, 2012 5:20 am
+0-
Hi,

I'm developing a prototype where I use the same Handlebars templates in a server side Java environment and a client side YUI environment.

I'm trying to figure out how to best deal with partials. A partial could on the server be something like

{{#with user}}
{{> /common/user }}
{{/user}}

I have so far been working on the assumption that all Handlebars templates are delivered through the loader, but I'm not sure how to deal with that in this case.

What I'm doing on the loader side is this:

Code:
YUI_config.groups.handlebars={
   base:'./js/handlebars/',
   combine:true,
   comboBase:comboBase,
   root:'handlebars/',
   patterns : {
        "-hbs" : {
            configFn : function(me) {
                me.path = me.name.replace("-hbs", ".hbs").replace("-","/");
                me.requires = [ "handlebars-base", "handlebars-compiler" ];
            }
        }
    }
};


So, when I use a template such as

Y.use('inbox-list-hbs')

it will be loaded as

inbox/list.hbs

Any suggestions?

Cheers,
Marc

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile

Re: Handlebars, partials and loader

Post Posted: Thu Jul 05, 2012 7:43 am
+0-
I like the idea of using pre-compiled templates in the browser. Where on the server you could compile the raw Handlebars templates into JavaScript functions wrapped as YUI modules. That way you only need the "handlebars-base" module and not the "handlebars-complier" (which is 27KB!), and Loader will know whether a template has been loaded or not since it's a true YUI module.
  [ 2 posts ]
Display posts from previous:  Sort by  
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