Skip to content

Commit a61e48b

Browse files
committed
minor #778 React components : working twig example (hedocode)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- React components : working twig example Hello ! The tutorial didn't work because I had not the following lines in my twig : {% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %} {% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %} | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Features and deprecations must be submitted against branch main. --> Commits ------- a7e8ae5 React components : working twig example
2 parents ba862ff + a7e8ae5 commit a61e48b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/React/doc/index.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Finally, to load your React components, add the following lines to ``assets/app.
6262
// they are not necessary.
6363
registerReactControllerComponents(require.context('./react/controllers', true, /\.(j|t)sx?$/));
6464
65-
That's it! Create an `assets/react/controllers/` directory and start creating your
65+
That's it! Create an ``assets/react/controllers/`` directory and start creating your
6666
React components.
6767

6868
Usage
@@ -77,6 +77,7 @@ React components located in the directory ``assets/react/controllers`` are regis
7777
React controller components.
7878

7979
You can then render any React controller component in Twig using the ``react_component``.
80+
8081
For example:
8182

8283
.. code-block:: javascript
@@ -88,11 +89,19 @@ For example:
8889
return <div>Hello {props.fullName}</div>;
8990
}
9091
91-
9292
.. code-block:: html+twig
9393

9494
{# templates/home.html.twig #}
95-
<div {{ react_component('MyComponent', { 'fullName': app.user.fullName }) }}></div>
95+
{% extends 'base.html.twig' %}
96+
97+
{% block body %}
98+
<div {{ react_component('MyComponent', { 'fullName': number }) }}>
99+
Loading... <i class="fas fa-cog fa-spin fa-3x"></i>
100+
</div>
101+
102+
{# Component living in a subdirectory: "assets/react/controllers/Admin/OtherComponent" #}
103+
<div {{ react_component('Admin/OtherComponent') }}></div>
104+
{% endblock %}
96105

97106
Backward Compatibility promise
98107
------------------------------

0 commit comments

Comments
 (0)