Created
June 21, 2019 11:13
-
-
Save Xilonz/3d3cc7db2e5e25ee8611cdfc58d15dba to your computer and use it in GitHub Desktop.
Sage 9 Carbon Field Blocks
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 | |
namespace App; | |
use Carbon_Fields\Field; | |
use Carbon_Fields\Block; | |
Block::make( __( 'Gutenberg Block' ) ) | |
->set_icon( 'format-chat') | |
->add_fields( array( | |
Field::make( 'rich_text', 'text', __( 'text', 'my-theme' ) ) | |
) ) | |
->set_render_callback( function ( $arg ) { | |
echo get_block_template('event_comment', $arg); | |
} ); | |
?> |
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 | |
namespace App; | |
function get_block_template( $template, $args ){ | |
$template = App\locate_template([$template.".blade.php", 'resources/views/partials/blocks/'.$template.'.blade.php']); | |
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) { | |
return apply_filters("sage/template/{$class}/data", $data, $template); | |
}); | |
$data = array_merge($data, $args); | |
if( $template ) | |
echo App\template($template, $data); | |
else | |
echo sprintf(__("Template for block %s not found", 'my-theme'), $template); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs to return empty array to avoid array_merge errors
$data = collect(get_body_class())->reduce(function ($data, $class) use ($template) { return apply_filters("sage/template/{$class}/data", $data, $template); }, []);