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

Adding conditional statements #21

Open
sunil-jhamnani-zz opened this issue Jan 15, 2018 · 1 comment
Open

Adding conditional statements #21

sunil-jhamnani-zz opened this issue Jan 15, 2018 · 1 comment

Comments

@sunil-jhamnani-zz
Copy link

I read about the module and also using it in my nodejs application in the email templates.
The only thing I want to ask is how can I add conditional statements in the templates, execute them and then fill in all the values?

Thanks!

@Matt-Esch
Copy link
Owner

Matt-Esch commented Jan 19, 2018

There are templating languages that embed conditionals into the language, this isn't one of those libraries, it's just a replacement engine.

If you want to use this library with conditionals then you would conditionally replace a sub-template.

format("{0}, you have {1} unread messages",
     getGreetingFor('Robert'),
     12
)
// -> Good evening Robert, you have 12 unread messages

function getGreetingFor(name) {
    var hour = (new Date()).getHours();
    if (hour >= 5 && hour < 12) {
        return format("Good morning {0}", name);
    } else if (hour >= 12 && hour < 17) {
        return format("Good afternoon {0}", name);
    } else {
        return format("Good evening {0}", name);
    }
}

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