Search code examples
javascriptjqueryjquery-templatesjsrender

Do conditional statements work in jsrender v1.0pre?


I am using jsrender: JsRender v1.0pre

Unfortunately, I cannot update to the latest version.

I wanted to use a conditional statement in my template like so:

{{if IsSometing}}
    SomeText
{{/if}}

However, this throws an error in the jsrender code:

if ( !current ) {
    throw "Expected block tag";
}

Will conditional statements work for templates in this version? If so, how? I have a jsfiddle here with the version I am using.

The conditional statement has to be moved into the first cell of the template to get the error.

Thanks


Solution

  • That is a very old version, and the syntax was different at that time.

    {{#if IsSomething}}
        SomeText
    {{/if}}
    

    If you really cannot update to the latest JsRender, then at least you need to grab the set of sample and demo pages from GitHub which correspond to your version. I'm not sure exactly which commit you are using. Here is one such page:

    https://github.com/BorisMoore/jsrender/blob/09e5f23eb089f067cc263b95dd1b06294796eec8/demos/step-by-step/04_if-else-tag.html

    Otherwise you are just going to be guessing at syntax and features for your version...