Accessing view in ajax loop

Making AJAX response handler that send rendered view back.

I know I can show view with view('partials.content')->render(), but how I can replicate following Blade syntax

@includeFirst(['partials.content-' . get_post_type(), 'partials.content'])

if I trow an array to view it just throw me an error… and I have several post types and this need to be dynamic

Make a partial containing that blade syntax and then call that partial.

I did think about going that route but wanted to double check is there is something like includeFirst on backend…
If all fail I will use this solution…

To the best of my knowledge there is no out-of-the-box solution to replicate the behavior of includeFirst outside of Blade. The logic it’s executing is very simple (“Does this file exist? If yes, load it; if not, load this other one”) so you could theoretically roll your own, but wrapping it in a secondary blade seems like a much simpler solution that leverages existing systems to me.

1 Like

I just want to thank you for help will go with your suggestion then…

1 Like

@alwaysblank can I ping you once again ?

I just noticed that in this custom view('partials.content')->render() loop it does not pull my ACF field unless I put them in partial as get_field('somefield', get_the_ID() )

I mean I can leave it like this, but do you maybe know why is that ?
My complete look look like this

if ($selected_posts) {
        while ($query->have_posts()) :
            echo view('partials.content-ajaxloadmore')->render();
            // echo $content;
        $block['featured_posts'] = ob_get_clean();

This topic was automatically closed after 42 days. New replies are no longer allowed.