Hello everyone !
I would like to know if it is possible to combine blade views with blocks defined in typescript.
To be clearer, let’s imagine I create a partials test.blade.php
, would there be a way to make @includeIf('partials.test')
in the block?
Thanks in advance for all your answers !
You mean using a Blade view as Gutenberg block?
This should be possible, as Gutenberg blocks support server-side rendering, the Blade-PHP template can therefore be rendered as HTML and printed as block.
I’m doing something sort-of like this (though very out of date) with ACF Gutenberg blocks here. It should be possible to loop over any Blade views an register blocks, right?
Can you give me a little more information?
If you want to use the rendered Blade-PHP templates as actual markup to be saved by a Gutenberg block (not server-side rendered), you have to render the Blade-PHP template first on the server and then pass it to Gutenberg frontend on the browser as a string (e.g. JavaScript template literals).
I had a similar task, letting the theme inject decorative elements into the editor DOM (not polluting the actual post content). I used HTML <template>s
for this, rendered from server-side.
IMHO markup for the theme/decorative purposes should be added server-side, either by post-processing from the theme and injecting DOM into the editor, than hard-saving it as page content. When the theme is changed, those elements would then simply disappear, without any need for changing the post content.
1 Like
Thanks for your answer, I will try to investigate this method!