You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm trying this library for the first time, and my question is: how can I rergister some sort of callback for section names? I wrote this code:
import mustache;
import std.stdio;
alias MustacheEngine!(string) Mustache;
string myFind (string parKey) {
writefln("%s not found", parKey);
return parKey;
}
int main() {
Mustache mustache;
auto context = new Mustache.Context;
mustache.handler = delegate string(string a) { return myFind(a); };
mustache.level = Mustache.CacheLevel.check;
stdout.rawWrite(mustache.render("basic", context));
return 0;
}
and I expected to see "in_ca" printed on stdout, but I don't. Thinking about it, it wouldn't make much sense either, but then what's the correct way to have mustache-d lookup in my code instead of searching the context for stuff? In my real code the context will be empty, just like in the example I posted.
Speaking of my custom handler myFind(), how can I signal an error if the key is not valid? Returning an empty string will not do it because the empty string could be a valid value. Should I just throw?
The text was updated successfully, but these errors were encountered:
Hello, I'm trying this library for the first time, and my question is: how can I rergister some sort of callback for section names? I wrote this code:
and I expected to see "in_ca" printed on stdout, but I don't. Thinking about it, it wouldn't make much sense either, but then what's the correct way to have mustache-d lookup in my code instead of searching the context for stuff? In my real code the context will be empty, just like in the example I posted.
Speaking of my custom handler myFind(), how can I signal an error if the key is not valid? Returning an empty string will not do it because the empty string could be a valid value. Should I just throw?
The text was updated successfully, but these errors were encountered: