Skip to content

Commit

Permalink
Merge pull request #51 from robmeijerink/fix-view-location
Browse files Browse the repository at this point in the history
bugfix view location sage 9
  • Loading branch information
MWDelaney authored Jan 13, 2021
2 parents 1d5794c + a59e330 commit 795527e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sage-acf-gutenberg-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App;

use Illuminate\Support\Str;

// Check whether WordPress and ACF are available; bail if not.
if (! function_exists('acf_register_block_type')) {
return;
Expand Down Expand Up @@ -191,17 +189,22 @@ function sage_blocks_callback($block, $content = '', $is_preview = false, $post_
$directories = apply_filters('sage-acf-gutenberg-blocks-templates', []);

foreach ($directories as $directory) {
$view = ltrim($directory, 'views/') . '/' . $slug;

if (isSage10()) {
$view = Str::replaceFirst('views/', '', $directory) . '/' . $slug;

if (\Roots\view()->exists($view)) {
// Use Sage's view() function to echo the block and populate it with data
echo \Roots\view($view, ['block' => $block]);
}

} else {
// Use Sage 9's template() function to echo the block and populate it with data
echo \App\template("${directory}/${slug}", ['block' => $block]);
try {
// Use Sage 9's template() function to echo the block and populate it with data
echo \App\template($view, ['block' => $block]);
} catch (\Exception $e) {
//
}
}
}
}
Expand Down

0 comments on commit 795527e

Please sign in to comment.