The {ignore} feature tells PAD not to parse curly braces {} as PAD tags within specific content. This is essential when working with JavaScript, JSON data, CSS, or any content that uses curly braces for its own syntax.

Why Use Ignore?

PAD normally parses all {} pairs as potential PAD tags. When your content contains curly braces that should be treated as literal text (like JavaScript code or JSON data), you need to tell PAD to ignore them.

Three Ways to Use Ignore

1. As a Tag Pair: {ignore}...{/ignore}

Wrap content in ignore tags to prevent PAD from parsing any curly braces within that block. This is commonly used for inline JavaScript or CSS.

Example 1: JavaScript with Object Literals

A brace followed by a space or a line end is left alone, but compact code - function f(){return 1;}, a{color:red} - is read as tags. Wrapped in {ignore}, the code is safe whichever way it is written:

PHP
HTML
fragments/ignore_1.pad
Result
{ignore}
<script>
const user = {
name: 'Alice',
role: 'Developer',
active: true
};

if (user.active) {
console.log('User: ' + user.name + ' (' + user.role + ')');
}
</script>
{/ignore}

<p>JavaScript executed. Check browser console for output.</p>

JavaScript executed. Check browser console for output.

Example 2: Inline CSS with Selector Blocks

CSS uses curly braces for selector blocks. Wrap in {ignore} to prevent PAD from parsing them:

PHP
HTML
fragments/ignore_2.pad
Result
{ignore}<style>
.example-box {
border: 2px solid #4CAF50;
padding: 20px;
margin: 10px 0;
border-radius: 8px;
background: #f0f8ff;
}

.example-box h4 {
margin: 0 0 10px 0;
color: #4CAF50;
}
</style>{/ignore}

<div class="example-box">
<h4>Styled Box</h4>
<p>This box uses the CSS defined above.</p>
</div>

Styled Box

This box uses the CSS defined above.

2. As a Pipe Function: | ignore

Apply ignore to the output of an expression to prevent PAD from parsing curly braces in that output. A variable's value needs it no more: values are text, their braces are never parsed (with $padProtectValues on, the default). It matters for what a tag answers as template source - an application tag that builds its $padContent, such as a {json 'products' | ignore} - and with $padProtectValues off.

Example 3: JSON Data in Attributes

JSON from a variable, passed to JavaScript through a data attribute - the pipe changes nothing here while values are protected, and keeps the braces safe when they are not:

PHP
fragments/ignore_4.php
HTML
fragments/ignore_4.pad
Result
<?php

// Sample data for JSON example
$userData = [
[
'id' => 1, 'name' => 'Alice', 'role' => 'Developer'],
[
'id' => 2, 'name' => 'Bob', 'role' => 'Designer'],
[
'id' => 3, 'name' => 'Charlie', 'role' => 'Manager']
];

// Encode to JSON with HTML escaping
$usersJson = htmlspecialchars(json_encode($userData), ENT_QUOTES, 'UTF-8');

?>
<div id="ignore-example-4" data-users="{echo $usersJson | ignore}"></div>

{ignore}<script>
const element = document.getElementById('ignore-example-4');
const users = JSON.parse(element.dataset.users);

const html = '<ul>' + users.map(user =>
'<li><strong>' + user.name + '</strong> - ' + user.role + '</li>'
).join('') + '</ul>';

element.innerHTML = html;
</script>{/ignore}

The JSON data was passed from PAD/PHP through a data attribute using {echo $usersJson | ignore}.

3. As an Option: ignore

Add the ignore option to a tag to prevent PAD from parsing curly braces in its content.

Example 4: A Tag with JSON in it

Use the {ignore} option on a tag to prevent PAD from parsing curly braces in its content:

PHP
HTML
fragments/ignore_5.pad
Result
{pad ignore}.box{color:red} .note{margin:0}{/pad}
.box{color:red} .note{margin:0}

Without the ignore option, PAD would read {color:red} as a tag - "there is no type named 'color'".

Best Practices

What Gets Ignored?

When ignore is active, PAD will NOT parse:

Everything within ignored content is treated as literal text.

Common Use Cases

Scenario Method Example
Inline JavaScript Tag Pair {ignore}<script>...{/ignore}
Inline CSS Tag Pair {ignore}<style>...{/ignore}
React/JSX Code Tag Pair {ignore}<script type="text/babel">...{/ignore}
JSON in Attributes Pipe Function data-json="{$jsonVar | ignore}"
JSON in a tag's content Option {pad ignore}

Important Notes

Summary

Method Syntax Use Case
Tag Pair {ignore}...{/ignore} Inline JavaScript, CSS, large blocks of code
Pipe Function {expression | ignore} Expression output contains JSON or curly braces
Option {tag ignore} Tag content should not be parsed

See Also