Skip to content

Kirby 4.4.1

$field->escape()

Escapes the field value to be safely used in HTML templates without the risk of XSS attacks

$field->escape(string $context = 'html'): Kirby\Content\Field

Parameters

Name Type Default Description
$context string 'html' Location of output (html, attr, js, css, url or xml)

Return type

Kirby\Content\Field

Aliases

You can use the following aliases for this field method in your template:

  • $field->esc(…)

Examples

<p><?= $page->text()->escape() ?></p>
<img alt="<?= $image->alt()->escape('attr') ?>" src="<?= $image->url() ?>" />
<section style="--columns: <?= $section->columns()->escape('css')">
...
</section>
<script>
let yourVariable = "<?= $page->jsVariable()->escape('js') ?>";

// ...
</script>
<iframe src="https://map.example.com/?lat=<?= $map->lat()->escape('url') ?>&lon=<?= $map->lon()->escape('url') ?>"></iframe>