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)