View facade in Blade extension

Posted 3 years ago by james2doyle

I am trying to use a Blade extension to render a View partial. This is my code so far:

Blade::extend(function($value, $compiler)
  $pattern = $compiler->createMatcher('navigation');
  $tree = Page::getTree();
  $template = View::make('Theme::decorators.nav-item')->with('pages', $tree)->render();
  return preg_replace($pattern, $template, $value);

The nav-item view is simply a nested UL list.

The problem is, using this trick, it seems to be causing my app to hang, my response goes empty.

I was previously just using a loop with a sprintf function, but using a view like this seems way nicer.

Does anyone have any experience doing this? Here are the things I have tried to far:

  • Using the View facade
  • Using the view() helper
  • Using a full path call to the View facade

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.