Chapters
40 Chapters
|
4:19:16
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
17.
Overriding Field Templates
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built on Symfony 6 but works great on Symfony 7!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"doctrine/doctrine-bundle": "^2.1", // 2.5.5
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.2.1
"doctrine/orm": "^2.7", // 2.10.4
"easycorp/easyadmin-bundle": "^4.0", // v4.0.2
"handcraftedinthealps/goodby-csv": "^1.4", // 1.4.0
"knplabs/knp-markdown-bundle": "dev-symfony6", // dev-symfony6
"knplabs/knp-time-bundle": "^1.11", // 1.17.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.5
"stof/doctrine-extensions-bundle": "^1.4", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.1
"symfony/console": "6.0.*", // v6.0.2
"symfony/dotenv": "6.0.*", // v6.0.2
"symfony/flex": "^2.0.0", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.2
"symfony/mime": "6.0.*", // v6.0.2
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.0.*", // v6.0.0
"symfony/security-bundle": "6.0.*", // v6.0.2
"symfony/stopwatch": "6.0.*", // v6.0.0
"symfony/twig-bundle": "6.0.*", // v6.0.1
"symfony/ux-chartjs": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.7", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.2
"twig/extra-bundle": "^2.12|^3.0", // v3.3.7
"twig/twig": "^2.12|^3.0" // v3.3.7
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.1
"symfony/debug-bundle": "6.0.*", // v6.0.2
"symfony/maker-bundle": "^1.15", // v1.36.4
"symfony/var-dumper": "6.0.*", // v6.0.2
"symfony/web-profiler-bundle": "6.0.*", // v6.0.2
"zenstruck/foundry": "^1.1" // v1.16.0
}
}
30 Comments
The same error :(
Whoops, we're sorry about that! It should be good now, I re-upload the video. Let us know if you still have some troubles with playing it
Cheers!
The error still here...
Please check my screen: https://ibb.co/fFPLk8S
Hey Dzianisr,
We're sorry about that! Looks like uploading was incomplete, I just re-uploaded this video again, now it should work!
Cheers!
No error. Thanks.
Thanks for confirming, and sorry for the inconvenience!
Cheers!
Hi, video not works : "The media could not be loaded, either because the server or network failed or because the format is not supported."
Hey Sébastien,
Thank you for reporting this! The video was re-uploaded, it should be fixed now. We're sorry for the inconveniences! Let us know if you still have any troubles with playing it.
Cheers!
It's good. Thanks victor
Thank you for confirming it works for you now!
Cheers!
The error came back :(
Hey Sébastien,
I'm sorry for that again! That's weird, but I just re-uploaded the video again, it should work now... at least it works for me.
Cheers!
Victor,
It works again!
Thanks!
Awesome!
Cheers!
I still have the issue.
Hey Stiff,
I fixed it again! We're sorry about that, now it should work.
Cheers!
Hi Victor,
Just to confirm, it is working now.
Best,
Stiff
Thanks for confirming!
Cheers!
is there a way to override all the IntegerField in my project via one template without calling >setTemplatePath evrytime i use IntegerField ?
Hey @ahmedbhs ,
Yes, it is! You can override that template on the CRUD controller level, or even on the Dashboard controller level - in
configureCrud()and calloverrideTemplate(). In theory, all the CRUD controllers linked to that dashboard will have use that overridden template. Or, I believe you can create a custom field based on the IntegerField where you will use your custom overridden template.Or more more ways, check the https://symfony.com/bundles/EasyAdminBundle/current/design.html#modifying-backend-templates - you can basically override the template on Symfony app level :)
Cheers!
Is there a way to override the template for global entities for all fields used in all forms? I don't want to use setTemplate every time.
Hey @ahmedbhs ,
I suppose you need to override the template in DashboardController, use
overrideTemplate()inconfigureCrud()method there. In theory, it should affect all your CRUD controllers linked to that specific dashboard. And since usually you have only one dashboard on practice - that should do the trick for all your CRUD controllers.I hope that helps!
Cheers!
Hi Ryan,
thanks for the awesome content as always!
We saw that we can use
setTemplatePath()to set our own template for a field in the ['index', 'detail'] pages.But is there a way to set a custom template for a field in the post pages? I tried to dig a little bit in the library but I got a bit lost.
If the answer is related to
setFormType()then how can we create our own TypeClass with its custom template?I want to convert my user roles json field to something like this: https://i.stack.imgur.com/26TlM.png
Thanks a lot in advanced :)
Hey Omar!
Excellent question! You're 100% right that
setTemplatePath()is NOT the way - that's only for "rendering"/displaying the field - it doesn't affect how the form renders at all.The form is rendered entirely via the form system. In fact, here is the template that, for example, renders the "edit" form: https://github.com/EasyCorp/EasyAdminBundle/blob/15c4125818b738785920c87029048ebf31e3b45c/src/Resources/views/crud/edit.html.twig#L61
And so, if you want to change how a field renders, you should create a custom form theme for this. I actually answered a similar question recently (honestly, I should have covered this in the tutorial) https://symfonycasts.com/screencast/easyadminbundle/association-many#comment-28419
The process is basically:
A) Use the web debug toolbar to find the name of the block(s) you can use to override how this one field renders
B) Create a template and render the field (and blocks) inside. This is probably the hardest part and has nothing to do with EasyAdmin - it is 100% about learning how to render a field in a custom way via a form theme https://symfony.com/doc/current/form/form_themes.html and https://symfonycasts.com/screencast/symfony-forms/form-theme-create
C) Call
->setFormTheme()on your field as an easy way to make sure your new template is included when the field is rendered.Let me know if this helps!
Cheers!
Got it!!!
Thanks a lot this amazing content, honestly I'v never enjoyed any course as much as I do in SymfonyCasts, It's super useful, full of actually important tips and simply fun! I really appreciate the content thx 🤩
Yay! So happy to hear - thanks for letting me know. And happy new year!
"Houston: no signs of life"
Start the conversation!