Templating engine like Blade not rendering ?
- This topic has 4 replies, 2 voices, and was last updated 4 years, 8 months ago by
Julien.
-
AuthorPosts
-
September 9, 2020 at 4:35 PM #21780
Julien
ParticipantHello,
I tried to use mb blocks with blade (templating engine from laravel) and code isn't interpreted.
I use a starter theme (Sage from Roots.io).
Render
And the code in my php template
<?php echo 'Hello World'; ?> @php echo 'Hello World'; @endphp {{ 'Hello World' }}
Do you think it's possible to fix that ?
Thanks
September 9, 2020 at 4:51 PM #21785Julien
ParticipantI found a solution with the render_callback, do you think it's possible to get the render_template value inside the callback ?
With this value I can make only one render_callback for all of my custom blocks.
There is the current solution for someone who need it
public function my_hero_callback($attributes, $is_preview = false, $post_id = null){ if (file_exists(get_theme_file_path("views/blocks/hero.blade.php"))) { echo \App\template("blocks.hero", [ 'attributes' => $attributes, 'is_preview' => $is_preview, 'post_id' => $post_id ]); } }
September 9, 2020 at 5:03 PM #21788Julien
ParticipantWe could maybe add information about render_template into the "set_block_data" function as follow ?
Base
private function set_block_data( &$attributes ) { $attributes['name'] = $this->id; $data = isset( $attributes['data'] ) ? $attributes['data'] : []; $this->storage->set_data( $data ); ActiveBlock::set_block_name( $this->id ); }
Into
private function set_block_data( &$attributes ) { $attributes['name'] = $this->id; $attributes['render_template'] = $this->render_template; $data = isset( $attributes['data'] ) ? $attributes['data'] : []; $this->storage->set_data( $data ); ActiveBlock::set_block_name( $this->id ); }
September 9, 2020 at 11:12 PM #21798Long Nguyen
ModeratorHi,
Please take a look at the function render_block() under the function set_block_data(),
private function render_block( $attributes = [], $is_preview = false, $post_id = null ) { $this->enqueue_block_assests(); if ( $this->render_callback ) { call_user_func( $this->render_callback, $attributes, $is_preview, $post_id ); return; } if ( file_exists( $this->render_template ) ) { include $this->render_template; } else { locate_template( $this->render_template, true ); } }
if the callback is available, it will run the callback and end the function before call the template so it is impossible to run a template inside the callback. But thanks for the idea, I will discuss with the developer team to support this case.
September 9, 2020 at 11:16 PM #21799Julien
ParticipantThanks for your response but I did the trick on my first reply. Did you see it ?
For the code on your reply, you didn't read code correctly, if the render_callback exist, the function render_callback is called and then stop because you have a "return;"
-
AuthorPosts
- You must be logged in to reply to this topic.