Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Outputting plain text as-is

Writing plain text that contains Oxiplate syntax (e.g., {%, {{, {#, {-}, or {_}) in a template can be frustrating. To avoid having to write {{ "{%" }} instead of {% repeatedly, the plaintext statement can be used instead.

All content within a plaintext statement will be output as-is, with the exception of the endplaintext tag, or something that appears to be the start of that tag:

  • {% endplaintext
  • {%- endplaintext
  • {%_ endplaintext

The whitespace separating endplaintext from the opening of the tag can be any whitespace normally allowed there. For example, {%_ endplaintext is perfectly acceptable.

Whitespace around both the open and close tags can be removed/replaced just like any other tag.

No other tags are recognized within the plain text block.

{% plaintext %}
{%- if true -%}
    {# Greeting -#}
    Hello {{ "world" }}!
{%- endif -%}

Goodbye.
{%- endplaintext -%}
extern crate oxiplate;

use oxiplate::prelude::*;

#[derive(Oxiplate)]
#[oxiplate = "plaintext.html.oxip"]
struct YourStruct;

assert_eq!(
    YourStruct.render()?,
    r#"
{%- if true -%}
    {# Greeting -#}
    Hello {{ "world" }}!
{%- endif -%}

Goodbye."#,
);

Ok::<(), ::core::fmt::Error>(())