Multiple menus

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

By Toledoh - November 16, 2014

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)

By claire - November 17, 2014

Hi Tim

You've only got to rename the functions there in the members chunk of code, if I recall right. Like so:

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

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


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

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

Claire Ryan
interactivetools.com

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

By Toledoh - November 17, 2014

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/

By Toledoh - November 19, 2014

Thanks for chasing it Claire!

Cheers,

Tim (toledoh.com.au)

By Toledoh - November 19, 2014

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)