Answer the question
In order to leave comments, you need to log in
Can't find error in menu block in tpl file?
There is a simple markup on html/css/js - responsive menu https://jsfiddle.net/martynuk/5tk6q8ty/ you need to place it in a tpl file.
I wrote the tpl code, but it doesn't work, I can't find the error. Who can help?
<?php if ($categories) { ?>
<div class="container">
<a class="toggleMenu" href="#">Menu</a>
<ul class="nav_menu">
<?php foreach ($categories as $category) { ?>
<li><?php if ($category['children']) { ?><div class="parent"<?php } ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li>
<a href="<?php echo $category['children'][$i]['href']; ?>">
<?php echo $category['children'][$i]['name']; ?></a>
</li>
<?php } ?>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
<div>
<?php } ?>
Answer the question
In order to leave comments, you need to log in
You have an extra closing curly brace. Use the open-close bracket count in the editor. Opening you have 7, closing 8. And the formatting of the code has moved a little - it's not clear which bracket closes what. The extra one comes before the last /li . I highlighted it in the code with a comment for clarity.
<?php if ($categories) { ?>
<div class="container">
<a class="toggleMenu" href="#">Menu</a>
<ul class="nav_menu">
<?php foreach ($categories as $category) { ?>
<li>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php for ($i = 0; $i < count($category['children']); $i++) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li>
<a href="<?php echo $category['children'][$i]['href']; ?>">
<?php echo $category['children'][$i]['name']; ?></a>
</li>
<?php } ?>
<?php } //for i < $j ?>
<?php } //for ($i = 0; $i < count ?>
</ul>
<?php } // if ($category['children']) #8 ?>
</li>
<?php } // foreach ($categories as $category) ?>
</ul>
<div>
<?php } ?>
Now the code looks like this, and with the adaptive menu, only the first item opens, the rest do not work
<?php if ($categories) { ?>
<div class="container">
<a class="toggleMenu" href="#">Menu</a>
<ul class="nav_menu">
<?php foreach ($categories as $category) { ?>
<li><?php if ($category['children']) { ?><?php } ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li>
<a href="<?php echo $category['children'][$i]['href']; ?>">
<?php echo $category['children'][$i]['name']; ?></a>
</li>
<?php } ?>
<?php } //for i < $j ?>
<?php } //for ($i = 0; $i < count ?>
</ul>
<?php } // if ($category['children']) #8 ?>
</li>
<?php } // foreach ($categories as $category) ?>
</ul>
<div>
<?php } ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question