{{ cms_code(name, { value: '...', class: '...' }) }}
Argument | Description | Data Type |
---|---|---|
name | The element identifier | String |
value (optional) | The code to be displayed | String |
class (optional) | A space-separated list of CSS classes to style the code component | String |
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
{{ cms_code('mycode', { value: 'function greet() {\n console.log("Hello, World!");\n}\ngreet();', class: 'text-sm' }) }}