This is my first question.
I'm building a simple dynamic menu using<li>
I'm working on a PHP based CMS (Kirby)
Kirby has predefined PHP functions (helpers)
I'm trying to output a <li>
for each page on the website:
<li class='active'><a href='page1'></a></li>
<li><a href='page2'></a></li>
<li><a href='page3'></a></li>
...
Im using a PHP function e($condition, $value)
to style the menu item only if that page isOpen()
// I need help here
<?php
foreach ($pages->visible() as $p):
echo "<li" . e($p->isOpen(), ' class="active"') . "><a href='" . $p->url() . "'></a></li>";
endforeach;
?>
The function is working but the css part class="active"
is printing OUTSIDE the <li>
on the final code
class="active"
<li>...</li>
<li>...</li>
<li>...</li>
I had this previous code that worked fine, but since i'm using display: inline-block
the menu had spaces betwes each block, since the following code was placing each <li>
in a new line.
// This code works
<?php foreach($pages->visible() as $p): ?>
<li <?php e($p->isOpen(), ' class="active"') ?> ><a href="<?php echo $p->url() ?>"></a></li>
<?php endforeach ?>
The reason i'm rewrinting the code is to remove the white space between the inline: block
elements.
I'm failing to concatenate the string in a way that the function works and print its results inside the <li>
tag.
I've searched here and also have read lots of Docs in php.net but nothing worked to me, I'm struggling with this for 2 days.
I'm expecting to learn better how and when to use concatenation and string operators.