How to display errors in overriden FOSUserBundle Registration form? - symfony

I have overridden the registration .twig files and it works except when the user doesn't enter matching passwords. How do I display any errors that are thrown by the registration process?

You can render your form errors by using form_errors function, like this:
{{ form_errors(form) }}
{{ form_errors(form.someField) }}
You should read this official documentation How to Customize Form Rendering to understand in deep how Symfony rendering your form view and how to custom the template as you want.

Related

Theming Drupal 8 - Loop through all posted articles and print specific section

I am trying to create my first Drupal 8 theme. On the frontpage, I want to list all articles with the title, summary, date posted, etc.
I more or less achieved this using views. Basically {{ page.content }} in twig, but found it to be really inflexible and I didn't really get the results that I wanted. What I want to do is just to iterate through all the articles and print each section of that article "manually". For instance:
{% for page in pages %}
{{ page.content.title }}
{{ page.content.datePosted }}
{{ page.content.body }}
{% endfor %}
So that I can have more control of what is happening and not making a lot of configuration in the views module when deploying. What is the best soltuion to achieve this? Thanks!
I recommend to use Views. Configure you view (filter by content type, etc.), you have a lot of parameters to achieve what you need.
Set the view to show "Content" and give it a view mode (you can use the default teaser, full, or create your own view mode). Then you can create a custom template for this :
node--xxxx--teaser.html.twig
In order to know how to name your custom template file, enable Twig Debugging in sites/default/services.yml. Set the debug variable to true. And clear cache. Then, you will see in source code the template name suggestion like this :
<!-- FILE NAME SUGGESTIONS:
* node--1--full.html.twig
* node--1.html.twig
x node--oeuvre--full.html.twig
* node--oeuvre.html.twig
* node--full.html.twig
* node.html.twig
-->
In your twig, you can do that kind of templating :
{{ content.my_field_image[0] }}
<h2>{{ node.title.value }}</h2>
<p>{{ content.body }}</p>

symfony twig form entity type checkbox column responsive

I have create a form with an entitytype with multiple choice. On my view i have all checkbox line by line. How can i make for exemple 3 checkbox on line if it's on tablet and 6 when it's on computer (using bootstrap col-) ?
I think you must rename your question to customizing form rendering in symfony.
so you can customize the form rendering by
{{ form_start(form) }}
<div class="someclass">
{{ form_widget(form.age) }}
</div>
{{ form_end(form) }}
Also you can work with form theming, there is already bootstrap theme with symfony you need to add in config.yml so all forms will use bootstrap
twig:
form_themes: ['bootstrap_3_layout.html.twig']
or do it for every template by adding
{% form_theme form 'bootstrap_3_layout.html.twig' %}
refer to How to Customize Form Rendering for more information
In fact i have not explain correctly .
Symfony display checkbox for entity field like this
checkbox display normaly by symfony
And i want this
checkbox in column

How to get {{ pages }} object in a modular page

Any thoughts on how to get the pages object in a modular page?
{{ dump(pages) }} returns null, but if I put the same statement in a regular page it works fine.
I have a page field that only gives me the URL of the selected pages and I need to get their title, ideally by just doing pages.find(link).title but "pages" is null for some reason.
For using page find, you have to use the singular page, not pages.
example:
{{ page.find('/contact').title }}
That said, you being not able to access the pages object from a modular page is probably a bug that should be reported as I see no reason why this would not work.

Symfony EasyAdmin - How to create custom field in form, displaying text informations

I am not sure, how to implement quite simple text field, into the configured form template. I have configured individual fields at yml file.
But what if I want, in the middle of the form, some text formatted informations (fetching data from another entities).
I have learned how to make custom edit template for the entities, by overriding "app/Resources/views/easy_admin/Entity/edit.html.twig".
But it allows me to change the template only around the form fields. The actual form is rendered by "{{ form(form) }}".
So, I need to edit this form() creation or customize the template somehow.
Is the only solution for this custom text field, to create custom form field type in Symfony? Or are there other methods to achieve this?
hope this helps
in the .twig file:
{% for name in value %}
<li>
<span>{{ include('#EasyAdmin/default/edit.html.twig', { value: name.name }) }}</span>
</li>
{% endfor %}
it means that the variable $name (collection) entered from the entity should be displayed inside this "for loop"
you can use the same technique to parse your desired html content
[edit.html.twig is located in app/Resources/views/easy_admin]

How different between "form" and "form_widget" in Twig?

I have read Twig Template Form Function and Variable Reference on the Symfony website. However, I don't quite understand the main different between them.
For example,
{{ form(form)}} and {{ form_widget(form) }}
So, my questions are:
How different between two of these, do they generate different HTML code? and when is one preferred over the other?
form(form) will generate the HTML for the form label, the form input, and also the form errors for all of the form elements.
form_widget(form.x) will only generate the HTML for the form input(ex. textbox), so you would have to generate the others yourself, or also include form_label(form.x) and form_error(form.x)
{{ form(form)}} is generate whole form with <form></form> tags and them fields at once. {{ form_widget(form) }} is used for generate specific field separately. Also read the docs about Symfony forms and Rendering each Field by Hand

Resources