Page 1 of 2

Making another Navbar for Header

Posted: Thu Dec 30, 2021 12:44 pm
by tessthepup
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

Re: Making another Navbar for Header

Posted: Thu Dec 30, 2021 4:49 pm
by 14Steve14
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.

Re: Making another Navbar for Header

Posted: Thu Dec 30, 2021 6:18 pm
by tessthepup
14Steve14 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.
I think I have caught them all but now doubting myself

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>');

Re: Making another Navbar for Header

Posted: Thu Dec 30, 2021 9:38 pm
by Kofod95
Not sure at all, but maybe:
tessthepup wrote: Thu Dec 30, 2021 6:18 pm

Code: 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;
    }
    
To:

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

Re: Making another Navbar for Header

Posted: Thu Dec 30, 2021 10:40 pm
by burt
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.

Re: Making another Navbar for Header

Posted: Thu Dec 30, 2021 11:51 pm
by mecinta
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.

Re: Making another Navbar for Header

Posted: Fri Dec 31, 2021 9:21 am
by tessthepup
Kofod95 wrote: Thu Dec 30, 2021 9:38 pm Not sure at all, but maybe:
tessthepup wrote: Thu Dec 30, 2021 6:18 pm

Code: 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;
    }
    
To:

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
already tried that with this result

Re: Making another Navbar for Header

Posted: Fri Dec 31, 2021 9:23 am
by tessthepup
mecinta wrote: Thu Dec 30, 2021 11:51 pm 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.
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');
    ?>

Re: Making another Navbar for Header

Posted: Fri Dec 31, 2021 9:26 am
by tessthepup
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.
Yes that does make sense although I would like to get this way working for my own sanity.

I dont see why the original navbar items are being called when I have duplicated and changed the navbar to a completely different one

Re: Making another Navbar for Header

Posted: Fri Dec 31, 2021 12:00 pm
by Kofod95
tessthepup wrote: Fri Dec 31, 2021 9:21 am already tried that
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