creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
900 stars 109 forks source link

equivalent for content_for :head and/or blocks like Ruby do #21

Closed mikesmullin closed 13 years ago

mikesmullin commented 14 years ago

is there an easy way to do include code in the layout HEAD tag from within a haml template / partial with Haml.js and/or Picard?

- content_for :head do
  = css_include 'groups/list'

%section.left
  - unless true # unless you have pending invitations
    %h1 Recommended Groups

i can see that templates are processed before their layout files are, and I imagine i could write some sort of helper, but wondering if this has already been thought of and provided for.

notice how haml is able to be rendered by nesting within the Do block

aaronblohowiak commented 13 years ago

There isn't a great way to do this because of how JavaScript's scoping rules work. We could support content_for by putting things onto the "this" object of the scope in which the template is rendered, but that would involve changing the function's binding at runtime which might break existing code, so I'm going to avoid that. Haml.js is a more strict conversion of a template into a function that takes a locals object and returns a string.