groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

How to get variable name? #108

Closed caoer closed 8 years ago

caoer commented 8 years ago

for example, my template is {{name}}, {{ name.firstName}}, the context is { "name": {"firstName": "cc"}}. How can I extract the variable name? My use case is that I want to watch for context's data change, if name.firstName is changed, the view will be updated.

groue commented 8 years ago

Hello @caoer.

GRMustache is a template rendering engine: once a template has been rendered with the data you provide, its job is done:

// Render a HTML string
NSString *html = [GRMustacheTemplate render:...];

It will render {{ name.firstName }} fine. In an NSString. And NSString does not automagically update itself when your data is updated.

You need to provide your own runtime to get the behavior you need.

caoer commented 8 years ago

hi @groue, thanks for your respond. Can you share some thoughts on how to provide my own runtime? If possible, I'd like to use GRMustache's code if possible. Best if I can hack into it's code and add such functionality. For example, once a string rendering is done, it reports how many variable are renderred and what are them. I've looked at GRMustacheTag, seems like the place to start?

groue commented 8 years ago

Remember to keep it simple. Mustache is a rendering engine. Not a runtime.