Using Timber / Twig in Carbon Fields blocks #1252
jasalt
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been shying away from getting too much into the block editor and found Timber theme framework awesome in recent projects, enjoying more similar development experience as Django, Rails etc. where re-using template parts is possible with very little overhead.
However, I needed to wrap things from my template into Gutenberg blocks for an content editor to use in the CMS side. With little testing it seems that it's simply a matter of requiring Timber (
composer require timber/timber
) and callingTimber::render('crb-timber-block.twig', $context);
in the CFset_render_callback
function.Simple example based on Carbon Fields block tutorial with layout defined in separate
.twig
template file:crb-timber-block.php
crb-timber-block.twig
Beta Was this translation helpful? Give feedback.
All reactions