-
Notifications
You must be signed in to change notification settings - Fork 11
Rule Reference
Alexander Tsybulsky edited this page Jan 31, 2017
·
2 revisions
The ABAP mustache mostly follows the original mustache spec - please, read it first if you are not familiar with mustache concept. Bellow is a brief listing of the rules.
-
{{name}}- variable in current context, if not found - search upper context levels -
{{{name}}}or{{& name}}- unescaped output (e.g. '<b>' will not be converted to '<b>') - escaping is done with
escape()call. Default format iscl_abap_format=>e_html_text. You can change this passing the format asiv_x_formatparameter tocreate()orconstructor(). Explicit empty value will disable escaping completely.
Section is a template like this:
{{#items}}
<b>{{name}}</b>
{{/items}}
- Tag with
#starts a section ({{#items}}), tag with/ends it ({{/items}}) - Section is rendered if the corresponding component
is not initial. The component may be a value, a structure or a table - In case of non-empty table the template inside a section is repeated for each license
- Section tag can also start with
^(like{{^items}}) - this mean inverted condition: the section is rendered if the componentIS initial - If a table consists only from one unnamed element (
DATA tab TYPE TABLE OF strings), the line content can be addressed with a special tag{{@tabline}}. E.g.{{#string_tab}}{{@tabline}},{{/string_tab}}
- If the section component is a table or a structure it is added on top of variable context stack.
- E.g the root structure contains component
nameand tableitems - each of items contain components
nameandprice - then
{{name}}tag inside the section will addressnameon item level - if it does not find it on item level it will search previous levels recursively
- E.g the root structure contains component
ABAP mustache supports partials. You may think of partials as of includes. Here is an example:
The root template:
Welcome to {{store_name}}!
{{>offers}}
The 'offers' template
{{#items}}
* {{name}} - {{price}}
{{/items}}
Partials are registered with add_partial() call (see API Reference). A Partial may contain other partials.
-
{{! ignore me }}- comment, is not rendered to output -
{{=<% %>=}}- changes tag delimiters, e.g. to<%, %>in the example
{{=<% %>=}}
Hello <% variable_name %>
<%={{ }}=%>
The below is mainly inspired by handlebars.js library and might be implemented in future.
- {{> partial someParameter="XXX" }} - parameters to sections and partials
- {{../permalink}} - explicit path to variable
- {{#if name}}{{else}} - if/else operator. Actually can be achieved by combination or
#and/section but looks better - {{#each list}}{{else}} - another syntaxic sugar for lists
- special tags for lists
{{@index}},{{@last}},{{@first}} - {{#with struc}} - another version of section, the feature is limiting upper level context search
Also potentially interesting improvements:
- Support references to objects and object attributes
- Support calling object methods for data