Chapters
27 Chapters
|
3:13:54
|
Login to bookmark this video
-
Course Code
Login or register to download the code!
Login or register to download the code!
-
This Video
Login or register to download the video!
Login or register to download the video!
-
Subtitles
Login or register to download the subtitles!
Login or register to download the subtitles!
-
Course Script
Login or register to download the script!
Login or register to download the script!
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!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.7", // v3.7.0
"doctrine/doctrine-bundle": "^2.7", // 2.7.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.13", // 2.13.3
"easycorp/easyadmin-bundle": "^4.4", // v4.4.1
"netgen/layouts-contentful": "^1.3", // 1.3.2
"netgen/layouts-standard": "^1.3", // 1.3.1
"pagerfanta/doctrine-orm-adapter": "^3.6",
"sensio/framework-extra-bundle": "^6.2", // v6.2.8
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.0
"symfony/console": "5.4.*", // v5.4.14
"symfony/dotenv": "5.4.*", // v5.4.5
"symfony/flex": "^1.17|^2", // v2.2.3
"symfony/framework-bundle": "5.4.*", // v5.4.14
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "5.4.*", // v5.4.6
"symfony/runtime": "5.4.*", // v5.4.11
"symfony/security-bundle": "5.4.*", // v5.4.11
"symfony/twig-bundle": "5.4.*", // v5.4.8
"symfony/ux-live-component": "^2.x-dev", // 2.x-dev
"symfony/ux-twig-component": "^2.x-dev", // 2.x-dev
"symfony/validator": "5.4.*", // v5.4.14
"symfony/webpack-encore-bundle": "^1.15", // v1.16.0
"symfony/yaml": "5.4.*", // v5.4.14
"twig/extra-bundle": "^2.12|^3.0", // v3.4.0
"twig/twig": "^2.12|^3.0" // v3.4.3
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "5.4.*", // v5.4.11
"symfony/maker-bundle": "^1.47", // v1.47.0
"symfony/stopwatch": "5.4.*", // v5.4.13
"symfony/web-profiler-bundle": "5.4.*", // v5.4.14
"zenstruck/foundry": "^1.22" // v1.22.1
}
}
4 Comments
Not sure if you made a mistake or not, but you are referring to a
bodytwig block when using the Full View block, but this is not correct, it should be content. In the text:The full view twig template (in my version at least, file:
@NetgenLayoutsStandard/nglayouts/themes/standard/block/full_view.html.twig) shows:Hey edin!
This is tricky stuff! When I saw your well-researched comment, I was thinking "he's right! How did I mess that up?".
But actually, the text is correct. But... you are ALSO correct :D. Here's what happens internally:
1) You're right that the template that is rendered for the
full_view.html.twiglooks like this:But this doesn't mean that this reads from your block called
content. It means that it prints thetwig_contentvariable (we'll talk about where this comes from in a minute) into a block calledcontent. Then, because this extendsblock.html.twig- that template. - https://github.com/netgen-layouts/layouts-core/blob/master/bundles/LayoutsBundle/Resources/views/nglayouts/themes/standard/block/block.html.twig#L9-L19 - just takes thecontentblock and renders it out.So this is all a really fancy way of basically just saying
{{ twig_content }}outside of any block.2) So where does
twig_contentcome from? First, each block has a "handler" class. The one for full view is this - https://github.com/netgen-layouts/layouts-standard/blob/master/lib/Block/BlockDefinition/Handler/Twig/FullViewHandler.php - nothing too important there, except that it implementsTwigBlockDefinitionHandlerInterface.3) When the blocks are rendering an event is fired. One of the listeners is this class: https://github.com/netgen-layouts/layouts-core/blob/master/bundles/LayoutsBundle/EventListener/BlockView/GetTwigBlockContentListener.php - notice this checks to see if the block handler implements
TwigBlockDefinitionHandlerInterface. If it does, it takes whatever the current template is that's rendering (it's an object, stored in thattwig_templateparameter), loops over$blockDefinition->getTwigBlockNames($block)and returns the contents of the first matching block. These contents become thetwig_contentvariable rendered in the template.4) So then, which block does
$blockDefinition->getTwigBlockNames($block)return? Well, if you look back atFullViewHandler:That doesn't tell us. It just says that the block names are injected via the constructor. Where is this service configured? Well, the argument is configured here: https://github.com/netgen-layouts/layouts-standard/blob/14af051a3f0bdc1f2be89014169a8b84148f1225/bundle/Resources/config/services/block_definitions.yaml#L21
So in the end, EITHER the
contentblock orbodyblock would be used (though the fact that you see a block calledcontentinsideful_view.html.twigis coincidental and not part of this process). If you had both acontentandbodyblock,contentwould win, so I suppose your answer is slightly more correct than mine, though I think I'll keep the text as it is :).Cheers!
Oh wow, thank you for the detailed explanation. I feel a bit guilty not doing this myself.
I am going to dig into this matter more myself when the full tutorial gets released.
For now, I am not able to render anything besides
contentTwig block in my template.I probably missed something as I am using my own playground project for this, but as I said, I will investigate this further with the tutorial project.
Thank you.
Hey edin!
No worries - I love to dig in, and your conclusion seemed logical to me too originally! Weird that only
contentTwig block is being used - let me know what you find out when you have a chance to investigate further.Cheers!
"Houston: no signs of life"
Start the conversation!