Last active
March 6, 2023 20:40
-
-
Save davidwebca/de35f136e12ace15a8fac556cb0d5d70 to your computer and use it in GitHub Desktop.
Add blade / override core block views in Sage 10.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add this to your filters.php file in a Sage 10 theme. | |
* It will look at "resources/views/core/{blockname}.blade.php | |
* and render the view with "block_content" and "block" as variables. | |
* | |
* You can also use View Composers built in Sage 10 to pass more | |
* data to the block as you wish. For ACF blocks, I recommend | |
* generoi/sage-acfblocks which is definitely the cleanest | |
* method to include ACF blocks in Sage 10 I found so far. | |
*/ | |
add_filter( 'render_block', function ( $block_content, $block ) { | |
if(\Roots\view()->exists($block['blockName'])) { | |
$block_content = \Roots\view($block['blockName'], [ | |
'block_content' => $block_content, | |
'block' => $block | |
])->render(); | |
} | |
return $block_content; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment