Reformat Code formats .isml files from their ISML and HTML tag structure. The default Indentation mode sets the indentation of each line and leaves the rest of the line as you wrote it. Full mode also tidies the inside of the lines. Formatting is free and works while the IDE indexes
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 itFormat a template
- Code › Reformat Code (
Cmd+Alt+L,Ctrl+Alt+L) formats the whole file, or only the selected lines when there's a selection. Each selected line gets the depth the whole template gives it, so a block pasted at the wrong level lands where it belongs - Code › Reformat File... (
Cmd+Alt+Shift+L,Ctrl+Alt+Shift+L) asks for the scope first. Reformat Code on a folder in the Project view formats every template in it - To format on every save, turn on Reformat code in Settings › Tools › Actions on Save and pick ISML among its file types
In Indentation mode a template keeps its number of lines. Full mode may wrap long start tags into more lines. Formatting a result again changes nothing in either mode
Indentation mode
- Tags with a body, such as
<isif>,<isloop>,<isdecorate>and<isobject>, indent their content one level, as nested HTML elements do <iselseif>and<iselse>line up with their<isif>, and the lines after them are indented one level- HTML elements pair their start and end tags as written, so a table whose rows come from an
<isloop>inside a cell indents correctly. Where ISML and HTML cross, such as a<div>opened in one branch and closed after</isif>, the ISML tags set the depth - The body of
<isscript>,<script>and<style>moves as a whole and keeps the relative indentation of its lines - Multi-line start tags,
${...}expressions and comments move with their first line. The body of<iscomment>moves as a whole too, where the VS Code formatter indents it - The content of
<pre>,<textarea>and multi-line JavaScript strings and template literals never moves
Tag text, attributes and expressions are never rewritten, and lines are never joined or split. Indentation follows Settings › Editor › Code Style › ISML › Tabs and Indents, or indent_size and indent_style in .editorconfig
Full mode
Full mode keeps the indentation of Indentation mode and also:
- Leaves one space between the attributes of a start tag 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 the attributes of ISML tags as the ISML attributes options say. HTML tags follow Settings › Editor › Code Style › HTML
- Formats
<isscript>,<script>and<style>bodies with the JavaScript and CSS formatters. A<script>with${...}inside keeps its lines, since the server fills them in - Keeps blank lines up to Keep blank lines of the HTML code style and removes spaces at line ends
<iscomment>, HTML comments and <pre> keep their text exactly. Text lines are never joined or split, and the code inside ${...} keeps its spacing unless you turn on Format ${} expressions with the JavaScript formatter:
<isprint value = "${ Resource.msg('x','y',null) }" encoding="off" />
<p>${a+b}</p><isprint value="${Resource.msg('x','y',null)}" encoding="off" />
<p>${a+b}</p><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" /><isinclude template="components/header"
sf-toolkit="off" /><isinclude
template="components/header"
sf-toolkit="off"
/>Wrap if long wraps only start tags that pass Hard wrap at. With Keep line breaks off, an ISML start tag you split over lines is joined back into one line
Code style options
Every option is in Settings › Editor › Code Style › ISML. Options marked full mode do nothing in Indentation mode
| Tab | Option | Default |
|---|---|---|
| ISML | Formatter mode: Indentation or Full | Indentation |
| ISML | Format ${} expressions with the JavaScript formatter (full mode) | Off |
| Tabs and Indents | Indent ISML tag bodies | On |
| Tabs and Indents | Indent <isscript> body | On |
| Tabs and Indents | Align <iselse> and <iselseif> with <isif>. Off indents the branches like body lines | On |
| Tabs and Indents | Do not indent children of: HTML element names, separated by commas | Empty, so every element indents its children |
| Spaces | Expression braces ${ } (full mode) | Off |
| Wrapping and Braces | Hard wrap at and Wrap on typing | The IDE defaults |
| Wrapping and Braces | ISML attributes (full mode): Do not wrap, Wrap if long, Chop down if long or Wrap always | Do not wrap |
| Wrapping and Braces | Align when multiline | Off |
| Wrapping and Braces | Keep line breaks | On |
| Wrapping and Braces | New line after the tag name when multiline | Off |
| Wrapping and Braces | New line before > when multiline | Off |
The HTML code style's own Do not indent children of list (html, body, thead, tbody, tfoot) doesn't apply to templates, so tables keep their depth
EditorConfig
Put the options in .editorconfig to share them with the team. Each one is ij_isml_ and the option name:
[*.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| Key | Values |
|---|---|
ij_isml_formatter_mode | indentation, full |
ij_isml_attribute_wrap | off, 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_end | true, false |
ij_isml_indent_tag_bodies, ij_isml_indent_script_body, ij_isml_align_branches_with_isif | true, false |
ij_isml_spaces_within_expression_braces, ij_isml_format_expressions | true, false |
ij_isml_do_not_indent_children_of | HTML element names, separated by commas |
Export › EditorConfig File on the code style page writes every option for you
Matching the VS Code formatter
Indentation mode follows the rules of the VS Code Indentation formatter, apart from the <iscomment> body, so a team that uses both editors gets the same templates. For the VS Code intellij-sfcc.isml.formatter.wrapAttributes values, set the same wrapping in Full mode, under ISML attributes for ISML tags and in the HTML code style for HTML tags:
| VS Code value | JetBrains settings |
|---|---|
preserve | Do not wrap |
preserve-aligned | Do not wrap with Align when multiline |
auto | Wrap if long |
aligned-multiple | Wrap if long with Align when multiline |
force | Wrap always |
force-aligned | Wrap always with Align when multiline |
force-expand-multiline | Wrap always with New line after the tag name and New line before > |