Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a73077

Browse files
committed
minor#20863 [Validator] Add docs for bridge twig validator#20836 (sfmok)
This PR was merged into the 7.3 branch.Discussion----------[Validator] Add docs for bridge twig validator#20836This pull request adds documentation for the new Twig Validator constraint introduced in the Twig Bridge.Changes:- Added a page to document the Twig validator constraint, including:- Installation instructions for the symfony/twig-bridge package.- Usage of the constraint in Symfony applications.- Detailed options available, including `message` and `skipDeprecations`.- Updated `index.rst` to include the new page under the "**Topics**" section for the **Twig Bridge.**Related Issue:[Issue#20836 - Add docs for Twig validator](#20836)Related PR:[Symfony PR #58805](symfony/symfony#58805) – Introduced the Twig validator constraint in the Twig Bridge.Commits-------ac9e20c Add docs for bridge twig validator#20836
2 parentsee79556 +ac9e20c commit6a73077

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

‎bridge/twig/validation.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Validating Twig Template Syntax
2+
===============================
3+
4+
The Twig Bridge provides a custom `Twig` constraint that allows validating
5+
whether a given string contains valid Twig syntax.
6+
7+
This is particularly useful when template content is user-generated or
8+
configurable, and you want to ensure it can be safely rendered by the Twig engine.
9+
10+
Installation
11+
------------
12+
13+
This constraint is part of the `symfony/twig-bridge` package. Make sure it's installed:
14+
15+
..code-block::terminal
16+
17+
$ composer require symfony/twig-bridge
18+
19+
Usage
20+
-----
21+
22+
To use the `Twig` constraint, annotate the property that should contain a valid
23+
Twig template::
24+
25+
use Symfony\Bridge\Twig\Validator\Constraints\Twig;
26+
27+
class Template
28+
{
29+
#[Twig]
30+
private string $templateCode;
31+
}
32+
33+
If the template contains a syntax error, a validation error will be thrown.
34+
35+
Constraint Options
36+
------------------
37+
38+
**message**
39+
Customize the default error message when the template is invalid::
40+
41+
// ...
42+
class Template
43+
{
44+
#[Twig(message: 'Your template contains a syntax error.')]
45+
private string $templateCode;
46+
}
47+
48+
**skipDeprecations**
49+
By default, this option is set to `true`, which means Twig deprecation warnings
50+
are ignored during validation.
51+
52+
If you want validation to fail when deprecated features are used in the template,
53+
set this to `false`::
54+
55+
// ...
56+
class Template
57+
{
58+
#[Twig(skipDeprecations: false)]
59+
private string $templateCode;
60+
}
61+
62+
This can be helpful when enforcing stricter template rules or preparing for major
63+
Twig version upgrades.

‎index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Topics
6060
web_link
6161
webhook
6262
workflow
63+
twig_bridge
6364

6465
Components
6566
----------

‎twig_bridge.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Twig Bridge
2+
===========
3+
4+
This bridge integrates Symfony with the Twig templating engine.
5+
6+
..toctree::
7+
:maxdepth:1
8+
9+
bridge/twig/validation

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp