News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

splitting menu items

Started by Orangine, July 31, 2012, 03:06:53 PM

Previous topic - Next topic

Orangine

Hello, I'm looking for some concept that will allow me to split the menu generated in Subs.php into two menus, as I would like to have more than one in my upcoming theme.  Something like Wordpress version of menus where you can have more than one displayed on the screen.
I'm looking for hints rather than working code, not sure if it's the right place to ask.


In case anyone wonders this is the code I'm referring to:
// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated'])
{
$buttons = array(
'home' => array(
'title' => $txt['home'],
'href' => $scripturl,
'show' => true,
'sub_buttons' => array(
),
'is_last' => $context['right_to_left'],
),
'help' => array(
'title' => $txt['help'],
'href' => $scripturl . '?action=help',
'show' => true,
'sub_buttons' => array(
),
),
'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => $context['allow_search'],
'sub_buttons' => array(
),
),
'admin' => array(
'title' => $txt['admin'],
'href' => $scripturl . '?action=admin',
'show' => $context['allow_admin'],
'sub_buttons' => array(
'featuresettings' => array(
'title' => $txt['modSettings_title'],
'href' => $scripturl . '?action=admin;area=featuresettings',
'show' => allowedTo('admin_forum'),
),
'packages' => array(
'title' => $txt['package'],
'href' => $scripturl . '?action=admin;area=packages',
'show' => allowedTo('admin_forum'),
),
'errorlog' => array(
'title' => $txt['errlog'],
'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging']),
),
'permissions' => array(
'title' => $txt['edit_permissions'],
'href' => $scripturl . '?action=admin;area=permissions',
'show' => allowedTo('manage_permissions'),
'is_last' => true,
),
),
),
'moderate' => array(
'title' => $txt['moderate'],
'href' => $scripturl . '?action=moderate',
'show' => $context['allow_moderation_center'],
'sub_buttons' => array(
'modlog' => array(
'title' => $txt['modlog_view'],
'href' => $scripturl . '?action=moderate;area=modlog',
'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
),
'poststopics' => array(
'title' => $txt['mc_unapproved_poststopics'],
'href' => $scripturl . '?action=moderate;area=postmod;sa=posts',
'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
),
'attachments' => array(
'title' => $txt['mc_unapproved_attachments'],
'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
),
'reports' => array(
'title' => $txt['mc_reported_posts'],
'href' => $scripturl . '?action=moderate;area=reports',
'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
'is_last' => true,
),
),
),
'profile' => array(
'title' => $txt['profile'],
'href' => $scripturl . '?action=profile',
'show' => $context['allow_edit_profile'],
'sub_buttons' => array(
'summary' => array(
'title' => $txt['summary'],
'href' => $scripturl . '?action=profile',
'show' => true,
),
'account' => array(
'title' => $txt['account'],
'href' => $scripturl . '?action=profile;area=account',
'show' => allowedTo(array('profile_identity_any', 'profile_identity_own', 'manage_membergroups')),
),
'profile' => array(
'title' => $txt['forumprofile'],
'href' => $scripturl . '?action=profile;area=forumprofile',
'show' => allowedTo(array('profile_extra_any', 'profile_extra_own')),
'is_last' => true,
),
),
),
'pm' => array(
'title' => $txt['pm_short'],
'href' => $scripturl . '?action=pm',
'show' => $context['allow_pm'],
'sub_buttons' => array(
'pm_read' => array(
'title' => $txt['pm_menu_read'],
'href' => $scripturl . '?action=pm',
'show' => allowedTo('pm_read'),
),
'pm_send' => array(
'title' => $txt['pm_menu_send'],
'href' => $scripturl . '?action=pm;sa=send',
'show' => allowedTo('pm_send'),
'is_last' => true,
),
),
),
'calendar' => array(
'title' => $txt['calendar'],
'href' => $scripturl . '?action=calendar',
'show' => $context['allow_calendar'],
'sub_buttons' => array(
'view' => array(
'title' => $txt['calendar_menu'],
'href' => $scripturl . '?action=calendar',
'show' => allowedTo('calendar_post'),
),
'post' => array(
'title' => $txt['calendar_post_event'],
'href' => $scripturl . '?action=calendar;sa=post',
'show' => allowedTo('calendar_post'),
'is_last' => true,
),
),
),
'mlist' => array(
'title' => $txt['members_title'],
'href' => $scripturl . '?action=mlist',
'show' => $context['allow_memberlist'],
'sub_buttons' => array(
'mlist_view' => array(
'title' => $txt['mlist_menu_view'],
'href' => $scripturl . '?action=mlist',
'show' => true,
),
'mlist_search' => array(
'title' => $txt['mlist_search'],
'href' => $scripturl . '?action=mlist;sa=search',
'show' => true,
'is_last' => true,
),
),
),
'login' => array(
'title' => $txt['login'],
'href' => $scripturl . '?action=login',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
),
'register' => array(
'title' => $txt['register'],
'href' => $scripturl . '?action=register',
'show' => $user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
'logout' => array(
'title' => $txt['logout'],
'href' => $scripturl . '?action=logout;%1$s=%2$s',
'show' => !$user_info['is_guest'],
'sub_buttons' => array(
),
'is_last' => !$context['right_to_left'],
),
);

Arantor

Well, for the bulk of it, it's just a case of duplicating the code in template_menu() in index.template.php which is responsible for display.

You don't have to rip the main menu definition apart, you just have to be careful about how you render it - like some of the DzinerStudio themes which don't display the register or logout buttons actually in the menu and instead simply skip that item in template_menu() and instead render it manually elsewhere in index.template.php.

Orangine

QuoteWell, for the bulk of it, it's just a case of duplicating the code in template_menu() in index.template.php which is responsible for display.
this I know
QuoteYou don't have to rip the main menu definition apart, you just have to be careful about how you render it - like some of the DzinerStudio themes which don't display the register or logout buttons actually in the menu and instead simply skip that item in template_menu() and instead render it manually elsewhere in index.template.php.
That's what I'm asking about - I don't really want to buy a theme just to see how it works, I was hoping someone might help me here.

Arantor

I'm sorry, I thought you just wanted hints rather than working code.

The code in template_menu() goes through the array. If you don't want to display an item, don't display it. Either use continue; to skip that item or something else, but whatever, all you have to do is not display it.

Screwing around with the core Subs.php definition 1) isn't directly possible in a theme without some serious jumping through hoops and 2) shouldn't be done anyway because it isn't necessary.

Adrek

I think that this tip that Arantor gave me a while ago may help you:

Quote from: Arantor on May 30, 2012, 04:40:53 PM
You could modify your theme's template_menu() to just not show the buttons in that theme... in the loop, check for the button's id and if it's login or register, just don't show it.

This is what some of DzinerStudio's premium themes do.


All we're really talking about is finding this line in template_menu:
foreach ($context['menu_buttons'] as $act => $button)

And adding after it:
if ($act == 'login' || $act == 'register')
  continue;


:)
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Orangine

Question is, how would I go about selecting what to display and what not to, it seems I'd have to do something like:
if ($something==$txt['home']) continue;
am I right?


edit: phantomm beat me to it

Orangine

Quote from: phantomm on July 31, 2012, 04:10:39 PM
I think that this tip that Arantor gave me a while ago may help you:

Quote from: Arantor on May 30, 2012, 04:40:53 PM
You could modify your theme's template_menu() to just not show the buttons in that theme... in the loop, check for the button's id and if it's login or register, just don't show it.

This is what some of DzinerStudio's premium themes do.


All we're really talking about is finding this line in template_menu:
foreach ($context['menu_buttons'] as $act => $button)

And adding after it:
if ($act == 'login' || $act == 'register')
  continue;


:)
I think this code doesn't take under consideration other language versions

Adrek

Why? It's looking for specified action, which is defined inside SMF and language doesn't matter.
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Orangine

ah yes, now I get it, I thought it refers to the language strings :P

Advertisement: