Skip to Content

Formatting

Format ISML templates in JetBrains IDEs - Indentation or Full mode, attribute wrapping, bare

Reformat Code formats .isml files from their ISML and HTML tag structure. Indentation mode (default) only sets each line's indentation. Full mode also tidies inside the lines. Formatting is free and works while the IDE indexes

Reformat Code (Cmd+Alt+L) in the default Indentation mode changes only the indentation. <iselse> lines up with its <isif>, and the text of every line stays as you wrote it

Format a template

  • Code › Reformat Code (Cmd+Alt+L, Ctrl+Alt+L) formats the file, or the selected lines at the depth the whole template gives them
  • Code › Reformat File... (Cmd+Alt+Shift+L, Ctrl+Alt+Shift+L) asks for the scope first. Reformat Code on a Project view folder formats every template in it
  • To format on save, turn on Reformat code in Settings › Tools › Actions on Save and pick ISML

Indentation mode keeps the line count, Full mode may wrap long start tags. Formatting twice changes nothing

Indentation mode

  • Tags with a body, such as <isif>, <isloop>, <isdecorate> and <isobject>, indent their content one level
  • <iselseif> and <iselse> line up with their <isif>, with the lines after them one level in
  • HTML start and end tags pair as written, so a table whose rows come from an <isloop> in a cell indents correctly. Where ISML and HTML cross, the ISML tags set the depth
  • <isscript>, <script> and <style> bodies move as a whole, keeping their relative indentation
  • Multi-line start tags, ${...} and comments move with their first line. The <iscomment> body moves as a whole too, where the VS Code formatter indents it
  • <pre>, <textarea> and multi-line JavaScript strings and template literals never move

Nothing is rewritten, joined or split, apart from the bare # escapes. Indentation follows Settings › Editor › Code Style › ISML › Tabs and Indents, or indent_size and indent_style in .editorconfig

Full mode

Full mode also:

  • Leaves one space between attributes and none around =. ISML tags keep a space before /> when they had one
  • Removes the spaces inside ${ }, or puts one on each side with Expression braces ${ }
  • Wraps and aligns ISML tag attributes per the ISML attributes options. HTML tags follow Settings › Editor › Code Style › HTML
  • Formats <isscript>, <script> and <style> bodies with the JavaScript and CSS formatters. A <script> containing ${...} keeps its lines
  • Keeps blank lines up to Keep blank lines of the HTML code style and removes trailing spaces

<iscomment>, HTML comments and <pre> keep their text. Code inside ${...} keeps its spacing unless Format ${} expressions with the JavaScript formatter is on:

<isprint value = "${ Resource.msg('x','y',null) }"  encoding="off"   />
<p>${a+b}</p>

Attribute wrapping

With ISML attributes (full mode) set to Wrap always, each attribute after the first goes on its own line:

<isinclude template="components/header"
    sf-toolkit="off" />

Wrap if long wraps only start tags past Hard wrap at. With Keep line breaks off, a split ISML start tag is joined back into one line

Bare # in template text

In both modes, Reformat Code writes each bare # of the template text as ${'#'}, or ${"#"} inside single quotes, the fix of the Unescaped # error. Code › Optimize Imports (Ctrl+Alt+O) writes the same escapes without formatting. A selection gets escapes only inside it

<a href="#reviews" style='color: #1a73e8'>Reviews</a>
<isprint value="${product.price}" formatter="#,##0.00" />

becomes

<a href="${'#'}reviews" style='color: ${"#"}1a73e8'>Reviews</a>
<isprint value="${product.price}" formatter="#,##0.00" />

formatter is an ISML attribute, so its # stays. To keep bare #, turn off Escape bare # as ${'#'}

Code style options

In Settings › Editor › Code Style › ISML. Options marked full mode do nothing in Indentation mode

TabOptionDefault
ISMLFormatter mode: Indentation or FullIndentation
ISMLFormat ${} expressions with the JavaScript formatter (full mode)Off
ISMLEscape bare # as ${'#'} (Reformat Code and Optimize Imports)On
Tabs and IndentsIndent ISML tag bodiesOn
Tabs and IndentsIndent <isscript> bodyOn
Tabs and IndentsAlign <iselse> and <iselseif> with <isif>. Off indents the branches like body linesOn
Tabs and IndentsDo not indent children of: HTML element names, separated by commasEmpty
SpacesExpression braces ${ } (full mode)Off
Wrapping and BracesHard wrap at and Wrap on typingThe IDE defaults
Wrapping and BracesISML attributes (full mode): Do not wrap, Wrap if long, Chop down if long or Wrap alwaysDo not wrap
Wrapping and BracesAlign when multilineOff
Wrapping and BracesKeep line breaksOn
Wrapping and BracesNew line after the tag name when multilineOff
Wrapping and BracesNew line before > when multilineOff

The HTML code style's own Do not indent children of list doesn't apply to templates

EditorConfig

Share the options through .editorconfig with ij_isml_ keys:

.editorconfig
[*.isml]
indent_size = 4
ij_isml_formatter_mode = full
ij_isml_attribute_wrap = on_every_item
ij_isml_align_attributes = true
ij_isml_spaces_within_expression_braces = false
ij_isml_format_expressions = true
KeyValues
ij_isml_formatter_modeindentation, full
ij_isml_attribute_wrapoff, normal (wrap if long), on_every_item (chop down if long), split_into_lines (wrap always)
ij_isml_align_attributes, ij_isml_keep_line_breaks_in_tags, ij_isml_new_line_after_tag_name, ij_isml_new_line_before_tag_endtrue, false
ij_isml_indent_tag_bodies, ij_isml_indent_script_body, ij_isml_align_branches_with_isiftrue, false
ij_isml_spaces_within_expression_braces, ij_isml_format_expressions, ij_isml_escape_bare_hashtrue, false
ij_isml_do_not_indent_children_ofHTML element names, separated by commas

Export › EditorConfig File on the code style page writes every option

Matching the VS Code formatter

Indentation mode follows the VS Code Indentation formatter, apart from the <iscomment> body. For VS Code intellij-sfcc.isml.formatter.wrapAttributes values, use Full mode with these settings, under ISML attributes for ISML tags and in the HTML code style for HTML tags:

VS Code valueJetBrains settings
preserveDo not wrap
preserve-alignedDo not wrap with Align when multiline
autoWrap if long
aligned-multipleWrap if long with Align when multiline
forceWrap always
force-alignedWrap always with Align when multiline
force-expand-multilineWrap always with New line after the tag name and New line before >

On this page