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.