Title: Using a .blade.php for rendering
Last modified: January 30, 2023

---

# Using a .blade.php for rendering

 *  Resolved [charliefishtank](https://wordpress.org/support/users/charliefishtank/)
 * (@charliefishtank)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/)
 * I am trying to use the Dynamic Render option with flexible content but due to
   the use of roots/sage I would like to still build the view with blade but in 
   doing so the output is just printing out the blade syntax rather than rendering
   it. Any suggestions to enable the use of blade files instead of the pure php 
   files?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fusing-a-blade-php-for-rendering%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16450225)
 * 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:
 *     ```wp-block-code
       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](https://www.acf-extended.com/features/fields/flexible-content/dynamic-render#hook-template-render-path),
   and the `acfe/flexible/render/before_template` [documentation here](https://www.acf-extended.com/features/fields/flexible-content/dynamic-render#hook-before-layout-render).
 * Hope it helps!
 * Have a nice day!
 * Regards.
 *  Thread Starter [charliefishtank](https://wordpress.org/support/users/charliefishtank/)
 * (@charliefishtank)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16451086)
 * 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…
 *     ```wp-block-code
       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
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16451282)
 * 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:
 *     ```wp-block-code
       $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.
 *  [charlottedrb](https://wordpress.org/support/users/charlottedrb/)
 * (@charlottedrb)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16621698)
 * Hi [@charliefishtank](https://wordpress.org/support/users/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.
 *  Thread Starter [charliefishtank](https://wordpress.org/support/users/charliefishtank/)
 * (@charliefishtank)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16685935)
 * Hi [@charlottedrb](https://wordpress.org/support/users/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();

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using a .blade.php for rendering’ is closed to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

## Tags

 * [Sage](https://wordpress.org/support/topic-tag/sage/)

 * 5 replies
 * 3 participants
 * Last reply from: [charliefishtank](https://wordpress.org/support/users/charliefishtank/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/using-a-blade-php-for-rendering/#post-16685935)
 * Status: resolved