So I have already found a solution to my problem, but I’m looking for an explanation as to why this does not work. I am trying to use a blade partial as the callback for wp_comments_list(). I figured out how to include the top-level partial from the callback function, but further @include statements cause an error. Here is some stripped down sample code.
post-comments.blade.php
<div class="entry-comments">
@php
$comments = get_comments(array('post_id' => $post->ID));
wp_list_comments(array('style' => 'div', 'reverse_top_level' => true, 'reverse_children' => true, 'callback' => 'Roots\Sage\Custom\comment_callback', 'end-callback' => 'Roots\Sage\Custom\comment_callback_close'), $comments);
@endphp
</div>
custom.php
function comment_callback($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
include \App\template_path(locate_template('views/partials/comment-callback.blade.php'));
unset($GLOBALS['comment']);
}
comment-callback.blade.php (shortened)
<div id="comment-{{ comment_ID() }}" class="row comment">
<div class="col-xs-2 col-sm-2 col-md-1">
@include('partials.entry-avatar')
</div>
...
Results in this error:
Call to a member function make() on null in /srv/www/blahblah/current/web/app/uploads/cache/compiled/6619436160ac8c890590bfa777f22d35a649ac88.php on line 3
and a peek into the compiled template
<div id="comment-<?php echo e(comment_ID()); ?>" class="row comment">
<div class="col-xs-2 col-sm-2 col-md-1">
<?php echo $__env->make('partials.entry-avatar', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
</div>
Now the solution is to call the child partials the same way the top level comment partial is called from the callback function, e.g.:
<div id="comment-{{ comment_ID() }}" class="row comment">
<div class="col-xs-2 col-sm-2 col-md-1">
@php(include \App\template_path(locate_template('views/partials/entry-avatar.blade.php')))
</div>
So the above works… but I just want to know what is going on here. Can anyone explain it to me?
Thanks