FunctionsCanopy

cms_code

The cms_code function is used to define a code component which can be edited on the Canopy editor.

{{ cms_code(name, { value: '...', class: '...' }) }}
ArgumentDescriptionData Type
nameThe element identifierString
value (optional)The code to be displayedString
class (optional)A space-separated list of CSS classes to style the code componentString

The class variable is only accessible in the code. All other variables are available in the Canopy editor.

Code component template

<code class={{ class }}>
  <pre>{{ value }}</pre>
</code>

Rendered HTML output

<code class="text-sm">
  <pre>
    function greet() {
        console.log("Hello, World!");
    }
    greet();
  </pre>
</code>

Example

index.html
 {{ cms_code('mycode', { value: 'function greet() {\n    console.log("Hello, World!");\n}\ngreet();', class: 'text-sm' }) }}

Last updated on