Ignore - Preventing PAD from Parsing Curly Braces
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 |
|---|---|---|
|
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 |
|---|---|---|
|
Styled BoxThis 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 |
|---|---|---|
|
|
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 |
|---|---|---|
|
.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
-
Always use {ignore} for JavaScript blocks - Any
<script>tag with JavaScript should be wrapped -
Use
| ignoreon a tag's JSON - When a tag answers JSON as template source, pipe it through ignore - Keep CSS in external files - But if inline CSS is needed, wrap in {ignore}
- Minimal scope - Only wrap what needs to be ignored, not entire templates
- Not needed for HTML - Regular HTML doesn't use curly braces, no ignore needed
What Gets Ignored?
When ignore is active, PAD will NOT parse:
-
{variableName}- Not treated as a variable reference -
{tagName}- Not treated as a PAD tag -
{if condition}...{/if}- Not treated as conditional -
{echo $expr}- Not treated as expression
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
-
Pairs nest - an inner
{ignore}...{/ignore}inside an ignore block is kept as literal text, and the block ends at its own closing tag - Use sparingly - Only use where necessary to avoid confusion
- External files preferred - For large JavaScript or CSS, use external files instead of inline code
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
-
{open} - Output opening brace
{ -
{close} - Output closing brace
} - {echo} - Evaluate expressions
- {data} - Define inline data