Hello,
Thanks for the feedback, and sorry for the late answer, I’m kinda busy with the upcoming patch lately.
I’m not a user of Blade, so I don’t really know how it works. Supposing Blade has its own function to blade_include() files, you could hook in the Flexible Content Dynamic Render to disallow the native include() function, and just use your own function instead.
Here is a usage example:
add_filter('acfe/flexible/render/template/name=my_flexible_content', 'my_flexible_content_render_file', 10, 4);
function my_flexible_content_render_file($file, $field, $layout, $is_preview){
// disallow the native Dynamic Render include()
// this tells ACFE that PHP files set in each layout settings do not exist
// which prevents the include() usage
return false;
}
add_action('acfe/flexible/render/before_template/name=my_flexible_content', 'my_flexible_content_render', 10, 3);
function my_flexible_content_render($field, $layout, $is_preview){
// get PHP file path set in the layout setting UI
$file = acf_maybe_get($layout, 'acfe_flexible_render_template');
if(!empty($file)){
// locate the file in theme
// $file_path = get_stylesheet_directory() . '/' . $file;
// use blade php include here
// ...
}
}
You’ll find the acfe/flexible/render/template documenation here, and the acfe/flexible/render/before_template documentation here.
Hope it helps!
Have a nice day!
Regards.
Hey Konrad,
This was a brilliant suggestion, should I be using both of those functions (filter and action) they both seem to work perfectly on their own just not sure which one to use?
For future blade/sage 10 users here is the adaption of the above filter to work with blade rendering…
add_filter('acfe/flexible/render/template', function ($file, $field, $layout, $is_preview) {
if (\View::exists($file)) {
echo \Roots\view($file, ['field' => $field, 'layout' => $layout, 'is_preview' => $is_preview])->render();
}
return false;
}, 10, 4);
Please do let me know if others have alternative methods/syntax that works better
Hello,
Well, it depends, some developers don’t want to output an echo in a filter and then return false, as it might look messy.
Your code will technically work, it’s just that some developers don’t like to mix filters (used to return a value) & actions (used to output something).
Additionally, if you’re interested, here is the schematics code order execution:
$file = filter: acfe/flexible/render/template
action: acfe/flexible/render/before_template
if($file){
include($file.php)
}
action: acfe/flexible/render/after_template
You’ll find these in /acf-extended/includes/acfe-template-functions.php:140 if needed.
Have a nice day!
Regards.
Hi @charliefishtank , I tried to use your code to make it work but unfortunately it doesn’t show my blade view at all in ACF Extended preview… Is it possible to have more informations on which path do you put in the field layout settings and if you add something in the view itself ?
Thank you in advance !
Have a nive day.
Hi @charlottedrb – great question, I should have added that part!
Using \Roots\view causes it to look in the resources/views folder so I pass in “[folder-name]/[file-name]” but exclude the .blade.php part i.e. blocks/hero so it would output:
echo \Roots\view(‘blocks/hero’, [‘is_preview’ => $is_preview, ‘field’ => $field])->render();