How can I return a view from an ajax call

Hey @frkparent - I think what you will need to do is render the Blade template using PHP in your AJAX hook, and then return the result.

You can render a Blade template in PHP using App\template(). Something like this:

add_filter('wp_ajax_load_posts', function () {
    echo App\template('partials.post-preview');
    wp_die();
});

If you need to pass data from the controller to the partial, take a look at @MWDelaney’s post here: Shortcodes that use Blade templates and get Controller data.

6 Likes