If tag

{% if <expr> %}
   ...
{% else if <expr> %}
   ...
{% else %}
   ...
{% end %}

The if tag evaluates the given <expr> and, if it's true, evaluates the given content block. If the expression evaluates to false, the next else if is evaluated. If none of them are true, the else block is evaluated.

Examples

First, let's assume we have the follow code to render the template set up:

  CarrotEngine engine = new CarrotEngine();
  engine.getConfig().setResourceLocator(...);

  Bindings bindings = new MapBindings(ImmutableMap.<String, Object>builder()
      .put("foo", true)
      .put("bar", false)
      .put("user", ImmutableMap.of(
          "id", 1234,
          "name", "Dean"))
      .build());

  System.out.println(engine.process("filename.html", bindings));

And the following template:

  {% if foo %}foo is true{% end %}
  {% if bar %}bar is true{% end %}
  {% if bar %}bar is true again{% else if foo %}foo is true again{% end %}
  {% if user.id < 2000 %}
    user.id is less than 2000
    {% if user.name == "Dean" %}user.name is Dean{% end %}
  {% end %}

It would output the following:

  foo is true

    foo is true again
    user.id is less than 2000
    user.name is Dean