Can't clear blade cache with embeded html in helpers.php

I’m working with Sage to try and convince my team to adopt it. There are times we choose to use a function to generate html with output buffering, for example, a nav:

// helpers.php
function get_main_nav()
{
    $nav_items = get_nav_items();

    ob_start();

    foreach ( $nav_items as $item )
    {
        $text = $item->title;
        $url  = $item->url;
        ?>
            <li class="navbar__item">
                <a href="<?= $url ?>" class="navbar__link">
                    <?= $text ?>
                </a>
            </li>
        <?
    }

    $nav =  ob_get_clean();

    return $nav;
}

// inc/nav.php
<ul>
    get_nav_items();

When I try to use a $ wp blade clear - I am getting an error “Parse error: syntax error, unexpected end of file”. It is being caused by the break in php for the output buffer loop. <<<HEREDOCs cause the problem as well. I was wondering if there is a way to do this in a function or if the standard way is with a blade partial include.

Without more info about your use case, it’s difficult to tell if there’s a more Blade-native way to implement it, but if you need to get a string that has some HTML you can make a partial, and then call it with \App\template('partials.your-partial-name', $array_of_data_for_partial). This evaluates your Blade with the data you pass and returns a string.