jamboree / bustache

C++20 implementation of {{ mustache }}
82 stars 10 forks source link

Empty string on one case but not a similar other one #24

Closed suy closed 3 years ago

suy commented 3 years ago

I'm still trying to find my way with the library, but when looking at examples of how to use it in the tests, I did some attempts and I got something very strange to me:

    using namespace bustache;
    context cont = {{"include", "{{$person}}customer{{/person}}"_fmt}};
    auto x = "Greetings {{<include}} IGNORED {{$person}}Alice{{/person}}{{/include}}"_fmt(nullptr);
    std::cout << "1 " << x.context(cont) << std::endl;
    auto y = "Greetings {{<include}} IGNORED {{$person}}Alice{{/person}}{{/include}}"_fmt;
    std::cout << "2 " << y(nullptr).context(cont) << std::endl;

I get:

1 
2 Greetings Alice

And I doing something wrong? I don't see why one usage should be different from the other, though I'm not familiar with the types returned in each case.

Thank you.

jamboree commented 3 years ago

The manipulator is not meant to be stored.

In the 1st case, you have dangling references to the format & value, that's the problem.