strange category menu / list alignment

5 posts by 2 authors in: Forums > CMS Builder
Last Post: September 14, 2011   (RSS)

Re: [rez] strange category menu / list alignment

By Jason - September 14, 2011

Hi rez,

I think the issue here is the placement of your last "endif".

In your foreach loop, you output _listItemStart before your if statement. However, you output _listItemEnd inside the else section of your if statement.

Try changing it to this instead:

<?php foreach ($menuCategoriesRecords as $menuCategoryRecord): ?>
<?php echo $menuCategoryRecord['_listItemStart'] ?>
<?php if ($menuCategoryRecord['_isSelected']): ?>
<strong><?php if (!$menuCategoryRecord['_hasChild']):?><a href="<?php echo $menuCategoryRecord['_link'] ?>"><?php endif; ?><?php echo $menuCategoryRecord['name'] ?><?php if (!$menuCategoryRecord['_hasChild']):?></a><?php endif; ?></strong>
<?php else: ?>
<?php if (!$menuCategoryRecord['_hasChild']):?><a href="<?php echo $menuCategoryRecord['_link'] ?>"><?php endif; ?><?php echo $menuCategoryRecord['name'] ?><?php if (!$menuCategoryRecord['_hasChild']):?></a><?php endif; ?>
<?php endif ?>
<?php echo $menuCategoryRecord['_listItemEnd'] ?>

<?php endforeach; ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] strange category menu / list alignment

By rez - September 14, 2011 - edited: September 14, 2011

sigh.. I need to improve my troubleshooting approach, i should see this type of thing by now. Yes, problem resolved. Thank you!

Re: [rez] strange category menu / list alignment

By Jason - September 14, 2011

Hi rez,

No problem. I don't know how many times I've made those types of mistakes myself.

One technique for reducing those types of problems (or at least making them easier to spot) is to put any loop or conditional structures on their own line.

For example, instead of

<?php if ($x == 2): ?> Do something here <?php else: ?> do something else <?php endif ?>

try
<?php if ($x == 2): ?>
Do Something
<?php else: ?>
Do Something Else
<?php endif ?>


This example is simple enough, but as soon as you have if statements nested inside other if statements that are inside a loop, it's easy to loose track of where you are. Indenting nested statements is also a good way of keeping your code clear.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] strange category menu / list alignment

By rez - September 14, 2011

Good point. Thanks again.