Closed ve3 closed 5 years ago
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>The UL</p> <ul id="the-list"> </ul> <template id="list-item"> <li {{#if notExistsOne}} no="no"{{/if}}>Is exists?</li> </template> <script src="handlebars.js"></script> <script> let data = { 'existsOne': 'yes', 'notExistsOne': 'no' }; let source = document.getElementById('list-item').innerHTML; let template = Handlebars.compile(source); let html = template(data); document.getElementById('the-list').innerHTML = html; </script> </body> </html>
Expect no="no" in html attribute but get this error in console.
no="no"
Error: Parse error on line 2: ... <li {{#if="" notexistsone}}=" -----------------------^ Expecting 'CLOSE_RAW_BLOCK', 'CLOSE', 'CLOSE_UNESCAPED', 'OPEN_SEXPR', 'CLOSE_SEXPR', 'ID', 'OPEN_BLOCK_PARAMS', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', 'SEP', got 'EQUALS'
OK, I'm wrong. The template tag must be ...
<script id="list-item" type="text/x-handlebars-template"> <li {{#if notExistsOne}} no="no"{{/if}}>Is exists?</li> </script>
It cannot work with <template> tag.
<template>
Expect
no="no"
in html attribute but get this error in console.