-
-
Notifications
You must be signed in to change notification settings - Fork 364
React components : working twig example #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/React/doc/index.rst
Outdated
.. code-block:: html+twig | ||
|
||
{# templates/home.html.twig #} | ||
|
||
{% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %} | ||
{% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. These ARE needed, but they're supposed to live in your base.html.twig
file and they should already be there by default (when you install Twig, it ships with a base.html.twig
that has these two lines). Did you not have these lines already in your base.html.twig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right !
Thank you for the precision, I didn't check the generated base.html.twig yet as the tutorial didn't extend it.
I added more informations so new users can make it work by copy-pasting, and still understand why it's needed with a link to related Encore documentation.
Sorry for the huge quantity of commits, I have been fighting with DOCtor RST, and he won by saying there is an error on a file I didn't change, on a line that does not have the problematic code :
src/LiveComponent/doc/index.rst ✘
581: Please use "html+twig" instead of "twig"
Have a good day !
Best regards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's see. Hmm. Earlier, on line 16 (first line under installation), we say:
Before you start, make sure you have
Symfony UX configured in your app
_.
That is where, in theory, we're trying to point you to "make sure you have Encore fully installed and working in your app". By putting that note there, we don't need to include those details later on. Adding them here "muddies" the docs because these notes are really about setting up Encore/Symfony UX, and not about actually installing React.
Did you see that note on line 16? Is it too subtle? Could you suggest a change to it? I'd very much like to improve that as needed, and not include the new notes here (and, btw, absolutely no problem with many commits - keep going - we automatically squash when we merge).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're trying to point you to "make sure you have Encore fully installed and working in your app"
I noticed that after, that's a bit of "recursion" but with attentive read it's clear enough.
these notes are really about setting up Encore/Symfony UX, and not about actually installing React
I agree with you that this page's responsibility is about Symfony React UX and therefore don't need to remind every dependencies such as Encore on it. According to that, I removed the Encore note and just kept the modified example extending base.html.twig.
Another thing, I noticed that they are no explanation for components in subfolders, I expected it to work by writing the component file name but we actually need to write the path to it from the root folder, can I document it in this pull request or may I create a new one for this ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing, I noticed that they are no explanation for components in subfolders, I expected it to work by writing the component file name but we actually need to write the path to it from the root folder, can I document it in this pull request or may I create a new one for this ?
Yea, this is something that should be mentioned - totally ok to include it here 👍
src/React/doc/index.rst
Outdated
.. code-block:: html+twig | ||
|
||
{# templates/home.html.twig #} | ||
|
||
{% block stylesheets %}{{ encore_entry_link_tags('app') }}{% endblock %} | ||
{% block javascripts %}{{ encore_entry_script_tags('app') }}{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's see. Hmm. Earlier, on line 16 (first line under installation), we say:
Before you start, make sure you have
Symfony UX configured in your app
_.
That is where, in theory, we're trying to point you to "make sure you have Encore fully installed and working in your app". By putting that note there, we don't need to include those details later on. Adding them here "muddies" the docs because these notes are really about setting up Encore/Symfony UX, and not about actually installing React.
Did you see that note on line 16? Is it too subtle? Could you suggest a change to it? I'd very much like to improve that as needed, and not include the new notes here (and, btw, absolutely no problem with many commits - keep going - we automatically squash when we merge).
<div {{ react_component('MyComponent', { 'fullName': number }) }}> | ||
Loading... <i class="fas fa-cog fa-spin fa-3x"></i> | ||
</div> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally fine with this change - it makes it more complete, without distracting too much
Done ! ✔️ |
src/React/doc/index.rst
Outdated
@@ -77,6 +77,9 @@ React components located in the directory ``assets/react/controllers`` are regis | |||
React controller components. | |||
|
|||
You can then render any React controller component in Twig using the ``react_component``. | |||
The first parameter is the path to the component from the root context folder, without extension at the end. | |||
The second is the component props object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about, instead of this note, we add a commented-out code example below - I'll suggest below
{% block body %} | ||
<div {{ react_component('MyComponent', { 'fullName': number }) }}> | ||
Loading... <i class="fas fa-cog fa-spin fa-3x"></i> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</div> | |
</div> | |
{# component living in a subdirectory: "assets/react/controllers/Admin/OtherComponent" #} | |
<div {{ react_component('Admin/OtherComponent') }}></div> |
The name Admin/OtherComponent
is correct here, right? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct ! I just verified it :)
Thank you @hedocode! |
You're welcome ! |
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 %}