Is it possible to use Twill with Twig (rcrowe) for frontend (block and module templates)?

… Blade is the antithesis of what template engine should be and I really don't get it why such a great framework like Laravel choose to support it natively. So is is possible to avoid it while creating block and module templates in Twill?
4 Replies
kallefrombosnia
kallefrombosnia6mo ago
If you dont need an admin block preview, you can exclude blade completly. You can create blocks without blade files. And for the frontend, you can extract block json data from the given module record/singleton and use it as headless or pass it down to your own preferenced templating engine in the controller.
Adam Mateusz Brożyński
Perfect. Seems that Twig works also for admin block previews so the only required interaction with Blade are block definitions in twill/blocks. resources/views/site/blocks/text.twig: <div class="prose"> {{ block.translatedInput('text')|raw }} </div>
ifox
ifox6mo ago
You don't need block definitions in blade either, you can you php classes with the form builder
Adam Mateusz Brożyński
Do you know what would be the right way to get component model instance so I could render it in twig template instead of blade? Edit: Ok, I've answered myself:
public function component($component): View
{
$className = "App\\View\\Components\\".$component;
$component = new $className;
return $component->render();
}
public function component($component): View
{
$className = "App\\View\\Components\\".$component;
$component = new $className;
return $component->render();
}
And now:
{{ component('MainMenu') }}
{{ component('MainMenu') }}
Want results from more Discord servers?
Add your server