Home Documentation Templates Examples Showcase GitHub ↗
Theme

Template language · Comments

Comments.

Nift comments are deliberately simple: they are removed from the generated output and nothing inside them executes. Use normal HTML comments when you want the comment to remain in the built page.

Comments never run Nift code.

A Nift comment can safely contain @input(...), @dep(...), $[...] or any other Nift-looking text. It is ignored completely.

Multiline Nift comments

Use <#-- and --#> for a multiline source comment:

<#--

    This is a Nift source comment.

    @input('partials/example.html')
    $[title]
    @dep('data/example.json')

--#>

Nothing inside the block is parsed or emitted. The input is not loaded, the metadata expression is not evaluated, and the dependency is not added.

Nift sourceGenerated output
before <#-- ignored --#> afterbefore after
<#-- $[title] --#>nothing

When multiline comments are useful

They are useful for source-only notes, temporarily disabling a section of Nift source, or commenting out syntax that may not currently be valid. Because the body is skipped entirely, it is safe for the comment to contain incomplete or otherwise meaningful Nift expressions.

Single-line Nift comments

For a comment that runs to the end of the line, Nift accepts either @# or @//:

@# this is a Nift comment
@// this is also a Nift comment

<p>This remains.</p>

Both forms are removed from the generated output and their contents are not parsed.

HTML comments are different

A normal HTML comment is part of the document you are generating:

<!-- This comment remains in the generated HTML. -->

Because the surrounding file is still processed by Nift, Nift expressions inside an HTML comment are still template source unless you escape them:

<!-- page title: $[title] -->

<!-- show the expression literally instead: \$[title] -->

The first example outputs the current page title inside the HTML comment. The second outputs the literal text $[title].

Choose based on where the comment belongs.

Use <#-- ... --#>, @# or @// for comments that exist only in Nift source. Use <!-- ... --> when the comment should be present in the generated HTML.

Comments work everywhere Nift parses source

The same comment forms work in tracked content, templates and files included with @input(...).

<header>
  @input('partials/navigation.html')
</header>

<#--

    Temporary source-only note:
    the old navigation lived in partials/navigation-v1.html.

--#>

This follows from Nift's composition model: both @content and @input parse their source as Nift rather than inserting raw text.

Unclosed multiline comments are build errors

A multiline comment must have its closing --#>. If it does not, Nift reports the source location instead of silently discarding the rest of the file:

error: while building docs/example
  content/docs/example.html:12
  open comment '<#--' has no close '--#>'

Quick reference

SyntaxMeaningEmitted?Body parsed?
<#-- ... --#>Multiline Nift commentNoNo
@# ...Single-line Nift commentNoNo
@// ...Single-line Nift commentNoNo
<!-- ... -->HTML commentYesYes