Multiple menus

7 posts by 2 authors in: Forums > CMS Builder
Last Post: November 19, 2014   (RSS)

Hi Guys,

I have a standard bootstrap menu being generated from a categories section called "pages":

// load pages
list($categories, $selectedCategory) = getCategories(array(
'tableName' => 'pages',
'ulAttributesCallback' => 'customMenuUlAttr', // ADVANCED: custom function to return ul attributes, eg: myUlAttr($category);
'liAttributesCallback' => 'customMenuLiAttr', // ADVANCED: custom function to return li attributes, eg: myLiAttr($category);
));

function customMenuUlAttr($category) {
return ($category['_hasParent'] && $category['depth'] == '1')? "class=\"dropdown-menu\" role=\"menu\"" : "" ;
}

function customMenuLiAttr($category) {
return ($category['_hasChild'] && $category['depth'] == '0')? 'class="dropdown"': "" ;
}

I've created another section called "members_pages" and I want to display a different menu if the user is logged in:

<?php if (!$CURRENT_USER): ?>

//Non-Members pages

<?php foreach ($categories as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<a href="
<?php if ($categoryRecord['redirect']): ?><?php echo $categoryRecord['redirect'] ?>
<?php else: ?><?php echo $categoryRecord['_link'] ?>
<?php endif ?>
"
<?php if ($categoryRecord['_hasChild'] && $categoryRecord['depth'] == '0'):?>
class="dropdown-toggle" data-toggle="dropdown"><?php echo $categoryRecord['name'] ?> <span class="caret"></span>
<?php else: ?>
><?php echo $categoryRecord['name'] ?>
<?php endif; ?>
</a>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>

<?php else: ?>

//Members pages

<?php foreach ($categories as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<a href="
<?php if ($categoryRecord['redirect']): ?><?php echo $categoryRecord['redirect'] ?>
<?php else: ?><?php echo $categoryRecord['_link'] ?>
<?php endif ?>
"
<?php if ($categoryRecord['_hasChild'] && $categoryRecord['depth'] == '0'):?>
class="dropdown-toggle" data-toggle="dropdown"><?php echo $categoryRecord['name'] ?> <span class="caret"></span>
<?php else: ?>
><?php echo $categoryRecord['name'] ?>
<?php endif; ?>
</a>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
<?php endif ?>

However, I cannot simply duplicate the functions as below -  I get "Cannot redeclare customMenuUlAttr()"

// load member pages
list($member_categories, $member_selectedCategory) = getCategories(array(
'tableName' => 'member_pages',
'ulAttributesCallback' => 'customMenuUlAttr', // ADVANCED: custom function to return ul attributes, eg: myUlAttr($category);
'liAttributesCallback' => 'customMenuLiAttr', // ADVANCED: custom function to return li attributes, eg: myLiAttr($category);
));

function customMenuUlAttr($category) {
return ($category['_hasParent'] && $category['depth'] == '1')? "class=\"dropdown-menu\" role=\"menu\"" : "" ;
}

function customMenuLiAttr($category) {
return ($category['_hasChild'] && $category['depth'] == '0')? 'class="dropdown"': "" ;
}

Can you suggest anything?

Cheers,

Tim (toledoh.com.au)

Thanks Claire.

It's progressed but I'm getting the error:  

Notice: Undefined index: _listItemStart in /home/qcwa/public_html/assets/modules/_topNavigation.php on line 39 test 1

Notice: Undefined index: _listItemStart in /home/qcwa/public_html/assets/modules/_topNavigation.php on line 39 test 2

"test 1" and "test 2" are the test page i've created in member_pages, so it's getting the content just fine.  However, it's not liking the 

<?php echo $member_selectedCategory['_listItemStart'] ?> 

Thoughts?

Cheers,

Tim (toledoh.com.au)

By claire - November 19, 2014

Sorry Tim, this isn't ringing any bells. I'll refer this to Dave, he knows the category setup pretty well.

--------------------

Claire Ryan
interactivetools.com

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

Thanks for chasing it Claire!

Cheers,

Tim (toledoh.com.au)

Hey Claire - I just tried again and it seems to be working based on you last advice!  Sorry!  and Thnaks!

Cheers,

Tim (toledoh.com.au)

By claire - November 19, 2014

Ah okay, no worries :) I'll tell Dave not to worry about it. Let us know if you're still having issues.

--------------------

Claire Ryan
interactivetools.com

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