XaminProject / handlebars.php

Handlebars processor for php
331 stars 132 forks source link

Mustache-style Context Lookups #162

Closed mAAdhaTTah closed 7 years ago

mAAdhaTTah commented 7 years ago

We're investigating "upgrading" from Mustache to Handlebars, and while it looks like the API to this project is very similar to Mustache.php, I came across some incompatibilities. Specifically, Mustache-style context lookups, whereby entering a block still allows you to reference a variable in the parent context. Mustache normally continues to look up the parent context until it finds the variable, whereas Handlebars appears to only look in the current context.

This makes it impossible to drop in Handlebars.php in place of Mustache.php. Two questions:

  1. How hard would it be to add this feature? If it's not too difficult, I may look into a PR for this.
  2. Are there any other incompatibilities between Mustache.php & Handlebars.php that you know of?
everplays commented 7 years ago
  1. Have a look at get method of Context class. It should not be very difficult to implement. Essentially, you need to use a while loop to move up the stack and try to get the variable.
  2. This implementation of handlebars is based on https://github.com/bobthecow/mustache.php so they should work pretty much the same. Other than the problem that you mentioned, I am not aware of anything else but it is possible.