Handlebars.js: How to modify the {{ symbol in the expression as other symbols

Created on 17 Sep 2018  ·  3Comments  ·  Source: handlebars-lang/handlebars.js

The current template is JSX syntax, and any { will be parsed, causing errors, and any configuration to replace the { symbol
I didn't find it in the document. Maybe I wasn't careful enough.

 // such
 style={{ textAlign: 'right' }}

 render() {
    return (
      <Form
        className="ant-advanced-search-form"
        onSubmit={this.handleSearch}
      >
        <Row gutter={24}>{this.getFields()}</Row>
        <Row>
          <Col span={24} style={{ textAlign: 'right' }}>
            <Button type="primary" htmlType="submit">Search</Button>
            <Button style={{ marginLeft: 8 }} onClick={this.handleReset}>
              Clear
            </Button>
          </Col>
        </Row>
      </Form>
    );
  }

Most helpful comment

You can escape {{ with a backslash: \{{, but there is no way to change the character completely

All 3 comments

If I understand correctly, you want the syntax of handlebars to change from {{expression}} to some other tag, like [[expression]] or even like ^&expression&^?

I'm not a contributor to the project but it looks like handlebars uses lex and yacc:

https://github.com/wycats/handlebars.js/blob/master/src/handlebars.l

This is the lex file, it converts text to representational symbols for use in the parser (yacc). If you want to change the characters which are matched for handlebars, then you'd have to replace the appropriate {{ and }} instances in the regular expressions with your preferred syntax.

I'm not sure which syntax of lex and yacc this project uses, but they're generally pretty similar to each other. I think the most common implementations these days are flex and byacc

If I understand correctly, you want the syntax of handlebars to change from {{expression}} to some other tag, like [[expression]] or even like ^&expression&^?

I'm not a contributor to the project but it looks like handlebars uses lex and yacc:

https://github.com/wycats/handlebars.js/blob/master/src/handlebars.l

This is the lex file, it converts text to representational symbols for use in the parser (yacc). If you want to change the characters which are matched for handlebars, then you'd have to replace the appropriate {{ and }} instances in the regular expressions with your preferred syntax.

I'm not sure which syntax of lex and yacc this project uses, but they're generally pretty similar to each other. I think the most common implementations these days are flex and byacc

Yes, that's what it means. As you say, you need to modify the source code instead of providing the external interface.
Mustache provides a similar interface.
Please excuse my poor English translation software.

You can escape {{ with a backslash: \{{, but there is no way to change the character completely

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nknapp picture nknapp  ·  3Comments

morgondag picture morgondag  ·  5Comments

janus-reith picture janus-reith  ·  3Comments

NickCis picture NickCis  ·  4Comments

rizen picture rizen  ·  6Comments