How do I get yielded content in a blade layout file as an HTML string from setup.php

During the draft_to_publish hook in my setup.php, I am running post content through a translation API to translate the content into various langauges. This is working OK when using
WP’s post->post_content. Indeed the content of the blog is translated.

However, this method is not necessarily translating everything I want on the page. For example, we render the category of the posts, the publication date and other data. In my layout, those sections are part of my yielded content and should be translated as well but they are not when using post->post_content.

BUT when I use the translation filter in the layout template file on $__env->getSection(‘content’), it translates everything I need on the page.

Therefore it seems that I needed to retrieve the yielded content from setup.php, but using $__env is undefined in that context.

Any idea how to retrieve the yielded content from a layout file in Sage 9? I know \App\template(‘layouts.app’) will return the entire file as a string, but I only want the yielded content.

I’ve tried a few different things without success.

First, from the ‘draft_to_publish’ hook, I tried printing one of the template files that are yielded like this:

error_log(print_r(App\template('single'),true))

However, it only returns an empty string.

Next I tried making a blade file called main.blade.php whose only job was to extend layouts.app and yield my content pages.

It looks like this:

@extends('layouts.app')

@section('main')
    @yield('content')
@endsection

I tried printing this page and it printed everything from the page BUT the yielded content I wanted (essentially it printed the header and footer for the site).

Any ideas on what I am missing here?