I’m wondering if theres a smarter way to do this. I have it working, but it seems like a lot of code for what I want.
I just want to list out pages that have a true for the featureinnav()
field, and if the page title contains the word ‘for’, wrap it in a ‘sup’ tag.
Here’s what ive got. How can i clean it up?
<ul>
<?php foreach ($pages->visible() as $sitenav): ?>
<?php if ($sitenav->featureinnav()->bool()): ?>
<?php
$string = $sitenav->title()->html();
$keys = array('for');
$patterns = array();
?>
<?php foreach ($keys as $key): ?>
<?php $patterns[] = '/\b('.$key.')\b/i'; ?>
<li><a <?php e($sitenav->isOpen(), ' class="active"') ?> href="<?= $sitenav->url() ?>"><?= preg_replace($patterns, '<sup>$0</sup>', $string) ?></a></li>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
</ul>