Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy lookup for section names #21

Open
KingDuckZ opened this issue Sep 30, 2014 · 1 comment
Open

Lazy lookup for section names #21

KingDuckZ opened this issue Sep 30, 2014 · 1 comment

Comments

@KingDuckZ
Copy link

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?

@repeatedly
Copy link
Owner

how can I rergister some sort of callback for section names?
[snip]
I expected to see "in_ca" printed on stdout, but I don't.

No support because mustache section is disabled when key is not exist.
So current behaviour is expected.

In my real code the context will be empty, just like in the example I posted.

Sorry, I can't imagine your case. Why do you use template engine with empty context?

how can I signal an error if the key is not valid?

Raising an error in your handler doesn't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants