Making another Navbar for Header
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Making another Navbar for Header
Hi Guys,
I have created a second navbar to contain more links.
I have copied and renamed includes/modules/content/navigation and includes/modules/navbar and also created a new navbar module.
All works fine apart from the new navbar is pulling in contents from the original navbar (see attached image)
I know I am missing something but not sure what.
Before I post all the code does anyone have quick goto to fix this off the top of their heads.
Thanks
I have created a second navbar to contain more links.
I have copied and renamed includes/modules/content/navigation and includes/modules/navbar and also created a new navbar module.
All works fine apart from the new navbar is pulling in contents from the original navbar (see attached image)
I know I am missing something but not sure what.
Before I post all the code does anyone have quick goto to fix this off the top of their heads.
Thanks
You do not have the required permissions to view the files attached to this post.
-
14Steve14
- Senior Contributor
- Posts: 922
- Joined: Fri Oct 25, 2019 7:01 pm
- Phoenix Version: v1.0.9.1
- Has thanked: 17 times
- Been thanked: 103 times
Re: Making another Navbar for Header
Just an idea, but have you also changed the names on the navbar in the module. In the original there are instances of NAVBAR which should also be changed to match the name of your new module. It will also then mean a change in the language files and possibly others.
I could be totally wrong though.
I could be totally wrong though.
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Making another Navbar for Header
I think I have caught them all but now doubting myself14Steve14 wrote: ↑Thu Dec 30, 2021 4:49 pm Just an idea, but have you also changed the names on the navbar in the module. In the original there are instances of NAVBAR which should also be changed to match the name of your new module. It will also then mean a change in the language files and possibly others.
I could be totally wrong though.
Code: Select all
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/
class cm_navbar_header extends abstract_executable_module {
const CONFIG_KEY_BASE = 'MODULE_CONTENT_NAVBAR_HEADER_';
public function __construct() {
parent::__construct(__FILE__);
}
public function execute() {
if ( defined('MODULE_CONTENT_NAVBAR_HEADER_INSTALLED') && !Text::is_empty(MODULE_CONTENT_NAVBAR_HEADER_INSTALLED) ) {
$navbar_modules_header = [];
foreach ( explode(';', MODULE_CONTENT_NAVBAR_HEADER_INSTALLED) as $nbm ) {
$class = pathinfo($nbm, PATHINFO_FILENAME);
$nav = new $class();
if ( $nav->isEnabled() ) {
$navbar_modules_header[] = $nav->getOutput();
}
}
if ( [] !== $navbar_modules_header ) {
$styles = [];
$styles[] = MODULE_CONTENT_NAVBAR_HEADER_STYLE_BG;
$styles[] = MODULE_CONTENT_NAVBAR_HEADER_STYLE_FG;
$styles[] = MODULE_CONTENT_NAVBAR_HEADER_FIXED;
$styles[] = MODULE_CONTENT_NAVBAR_HEADER_COLLAPSE;
$navbar_style = implode(' ', $styles);
$tpl_data = [ 'group' => $this->group, 'file' => __FILE__ ];
include 'includes/modules/content/cm_template.php';
}
}
switch (MODULE_CONTENT_NAVBAR_HEADER_FIXED) {
case 'fixed-top':
$custom_css = '<style>body { padding-top: ' . MODULE_CONTENT_NAVBAR_HEADER_OFFSET . ' !important; }</style>';
break;
case 'fixed-bottom':
$custom_css = '<style>body { padding-bottom: ' . MODULE_CONTENT_NAVBAR_HEADER_OFFSET . ' !important; }</style>';
break;
default:
return;
}
// workaround; padding needs to be set last
$GLOBALS['Template']->add_block($custom_css, 'footer_scripts');
}
protected function get_parameters() {
return [
'MODULE_CONTENT_NAVBAR_HEADER_STATUS' => [
'title' => 'Enable Navbar Header Module',
'value' => 'True',
'desc' => 'Should the Navbar be shown? ',
'set_func' => "Config::select_one(['True', 'False'], ",
],
'MODULE_CONTENT_NAVBAR_HEADER_STYLE_BG' => [
'title' => 'Background Colour Scheme',
'value' => 'bg-light',
'desc' => 'What background colour should the Navbar have? See <a target="_blank" rel="noreferrer" href="https://getbootstrap.com/docs/4.6/utilities/colors/#background-color"><u>colors/#background-color</u></a>',
'set_func' => "Config::select_one(['bg-primary', 'bg-secondary', 'bg-success', 'bg-danger', 'bg-warning', 'bg-info', 'bg-light', 'bg-dark', 'bg-white'], ",
],
'MODULE_CONTENT_NAVBAR_HEADER_STYLE_FG' => [
'title' => 'Link Colour Scheme',
'value' => 'navbar-light',
'desc' => 'What foreground colour should the Navbar have? See <a target="_blank" rel="noreferrer" href="https://getbootstrap.com/docs/4.6/components/navbar/#color-schemes"><u>navbar/#color-schemes</u></a>',
'set_func' => "Config::select_one(['navbar-dark', 'navbar-light'], ",
],
'MODULE_CONTENT_NAVBAR_HEADER_FIXED' => [
'title' => 'Placement',
'value' => 'default',
'desc' => 'Should the Navbar be Fixed/Sticky/Default behaviour? See <a target="_blank" rel="noreferrer" href="https://getbootstrap.com/docs/4.6/components/navbar/#placement"><u>navbar/#placement</u></a>',
'set_func' => "Config::select_one(['fixed-top', 'fixed-bottom', 'sticky-top', 'default'], ",
],
'MODULE_CONTENT_NAVBAR_HEADER_OFFSET' => [
'title' => 'Placement Offset',
'value' => '4rem',
'desc' => 'Offset if using fixed-* Placement.',
],
'MODULE_CONTENT_NAVBAR_HEADER_COLLAPSE' => [
'title' => 'Collapse',
'value' => 'navbar-expand-sm',
'desc' => 'When should the Navbar Show? See <a target="_blank" rel="noreferrer" href="https://getbootstrap.com/docs/4.6/components/navbar/#how-it-works"><u>navbar/#how-it-works</u></a>',
'set_func' => "Config::select_one(['navbar-expand', 'navbar-expand-sm', 'navbar-expand-md', 'navbar-expand-lg', 'navbar-expand-xl'], ",
],
'MODULE_CONTENT_NAVBAR_HEADER_SORT_ORDER' => [
'title' => 'Sort Order',
'value' => '10',
'desc' => 'Sort order of display. Lowest is displayed first.',
],
];
}
}
Code: Select all
<nav class="navbar <?= $navbar_style ?> cm-navbar-header">
<div class="<?= BOOTSTRAP_CONTAINER ?>">
<?php
$Template =& Guarantor::ensure_global('Template');
if ($Template->has_blocks('navbar_modules_home')) {
echo '<div class="navbar-header">' . PHP_EOL;
echo $Template->get_blocks('navbar_modules_home');
echo '</div>' . PHP_EOL;
}
?>
<div class="collapse navbar-collapse" id="collapseCoreNav">
<?php
if ($Template->has_blocks('navbar_modules_left')) {
echo '<ul class="navbar-nav mr-auto">' . PHP_EOL;
echo $Template->get_blocks('navbar_modules_left');
echo '</ul>' . PHP_EOL;
}
if ($Template->has_blocks('navbar_modules_center')) {
echo '<ul class="navbar-nav mx-auto">' . PHP_EOL;
echo $Template->get_blocks('navbar_modules_center');
echo '</ul>' . PHP_EOL;
}
if ($Template->has_blocks('navbar_modules_right')) {
echo '<ul class="navbar-nav ml-auto">' . PHP_EOL;
echo $Template->get_blocks('navbar_modules_right');
echo '</ul>' . PHP_EOL;
}
?>
</div>
</div>
</nav>
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/
?>
Code: Select all
define('MODULE_CONTENT_NAVBAR_HEADER_TITLE', 'Navigation Bar');
define('MODULE_CONTENT_NAVBAR_HEADER_DESCRIPTION', 'Show the Navigation Bar on your site. <div class="alert alert-warning">This module has a number of Sub Modules which must also be installed.<br><br>Admin > Modules > Navbar Modules</div>');
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Making another Navbar for Header
Not sure at all, but maybe:
Repeated for all blocks?
//Daniel
To:tessthepup wrote: ↑Thu Dec 30, 2021 6:18 pmCode: Select all
if ($Template->has_blocks('navbar_modules_home')) { echo '<div class="navbar-header">' . PHP_EOL; echo $Template->get_blocks('navbar_modules_home'); echo '</div>' . PHP_EOL; }
Code: Select all
if ($Template->has_blocks('navbar_modules_header_home')) {
echo '<div class="navbar-header">' . PHP_EOL;
echo $Template->get_blocks('navbar_modules_header_home');
echo '</div>' . PHP_EOL;
}
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- burt
- Core Team
- Posts: 4551
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Making another Navbar for Header
It would probably be simpler to make yourself some extra navbar modules to suit your needs and install them all into the normal navbar area.
Then turn off (uninstall) the navbar and make yourself a new header module that outputs the navbars modules (I hope this makes sense)? In effect your new header content module simply outputs what would be in the navbar if the navbar was turned on.
Then turn off (uninstall) the navbar and make yourself a new header module that outputs the navbars modules (I hope this makes sense)? In effect your new header content module simply outputs what would be in the navbar if the navbar was turned on.
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
-
mecinta
- Member
- Posts: 5
- Joined: Sun Nov 07, 2021 1:28 pm
- Phoenix Version:
- Has thanked: 6 times
- Been thanked: 4 times
Re: Making another Navbar for Header
This method will probably achieve the same result as you require.
First, make a copy of template_top.php and save it as a override template. Move a line as shown in the picture attached.
First, make a copy of template_top.php and save it as a override template. Move a line as shown in the picture attached.
You do not have the required permissions to view the files attached to this post.
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Making another Navbar for Header
already tried that with this resultKofod95 wrote: ↑Thu Dec 30, 2021 9:38 pm Not sure at all, but maybe:To:tessthepup wrote: ↑Thu Dec 30, 2021 6:18 pmCode: Select all
if ($Template->has_blocks('navbar_modules_home')) { echo '<div class="navbar-header">' . PHP_EOL; echo $Template->get_blocks('navbar_modules_home'); echo '</div>' . PHP_EOL; }Code: Select all
if ($Template->has_blocks('navbar_modules_header_home')) { echo '<div class="navbar-header">' . PHP_EOL; echo $Template->get_blocks('navbar_modules_header_home'); echo '</div>' . PHP_EOL; }
Repeated for all blocks?
//Daniel
You do not have the required permissions to view the files attached to this post.
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Making another Navbar for Header
thanks but that was the first thing I did otherwise the new navbar would not show
Code: Select all
<?php
echo $OSCOM_Hooks->call('siteWide', 'injectBodyStart');
echo $oscTemplate->getContent('header_prefix');
echo $oscTemplate->getContent('navigation');
?>
<div id="bodyWrapper" class="<?php echo BOOTSTRAP_CONTAINER; ?> pt-2">
<?php
echo $OSCOM_Hooks->call('siteWide', 'injectBodyWrapperStart');
echo $OSCOM_Hooks->call('siteWide', 'injectBeforeHeader');
require $oscTemplate->map_to_template('header.php', 'component');
echo $oscTemplate->getContent('navigation_header');
echo $OSCOM_Hooks->call('siteWide', 'injectAfterHeader');
?>
- tessthepup
- Certified Developer
- Posts: 382
- Joined: Mon Mar 01, 2021 5:55 pm
- Phoenix Version:
- Has thanked: 47 times
- Been thanked: 62 times
Re: Making another Navbar for Header
Yes that does make sense although I would like to get this way working for my own sanity.burt wrote: ↑Thu Dec 30, 2021 10:40 pm It would probably be simpler to make yourself some extra navbar modules to suit your needs and install them all into the normal navbar area.
Then turn off (uninstall) the navbar and make yourself a new header module that outputs the navbars modules (I hope this makes sense)? In effect your new header content module simply outputs what would be in the navbar if the navbar was turned on.
I dont see why the original navbar items are being called when I have duplicated and changed the navbar to a completely different one
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Making another Navbar for Header
It is better that it shows nothing than it shows something wrong. As far as I remember, the modules are called from table.configuration, with a key that is similar to MODULES_NAVBAR_INSTALLED - Do you have a new one like this for your new navbar_header-modules?
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide