Advertisement
stom66

Bootstrap4 Nav

Nov 14th, 2017
481
0
Never
10
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 4.15 KB | None | 0 0
  1. {*
  2. *   Template name: Bootstrap4 Nav
  3. *   -------------------------------------
  4. *
  5. *   This is the default template for use with the "Navigator" module. It is capable of generating
  6. *   the three stock Bootstrap Navbar types: default, static and fixed. It can also be customised
  7. *   with the included Bootstrap4 classes for light and dark.
  8.  
  9. *   Customisations should be made in the "Bootstrap4 Settings" template and NOT in this file, and
  10. *   the following can be done there:
  11. *
  12. *    - Change navbar position
  13. *    - Change navbar brand text
  14. *    - Change navbar brand logo
  15. *    - Change toggler alignment
  16. *    - Switch dark/light Bootstrap theme
  17. *
  18. *   Note: this template should be set as the "default" template of its type for the Bootstrap4 theme
  19. *
  20. *   Part of the CMSMS Bootstrap4 template by stom | stom66.co.uk
  21. *}
  22. {$default_navbar_style = $default_navbar_style|default:"default" scope=global}
  23. {function name=Nav_menu depth=1}{strip}
  24.     {foreach $data as $node}
  25.         {* setup classes for the anchor and list item *}
  26.         {assign var='liclass' value='nav-item'}
  27.  
  28.         {if $depth < 1}
  29.             {assign var='aclass' value='nav-link'}
  30.         {else}
  31.             {assign var='aclass' value='dropdown-item'}
  32.         {/if}
  33.  
  34.         {if $node->current}
  35.             {assign var='liclass' value=$liclass|cat:' active'}
  36.             {assign var='aclass' value=$aclass|cat:' active'}
  37.         {/if}
  38.  
  39.         {if $node->parent}
  40.             {assign var='liclass' value=$liclass|cat:' active'}
  41.             {assign var='aclass' value=$aclass|cat:' active'}
  42.         {/if}
  43.  
  44.         {if $node->children_exist && isset($node->children) && $depth < 1}
  45.             {assign var='liclass' value=$liclass|cat:' dropdown'}
  46.             {assign var='aclass' value=$aclass|cat:' dropdown-toggle'}
  47.         {/if}
  48.  
  49.         {* build the menu item node *}
  50.         {if $node->type == 'sectionheader'}
  51.             {if $depth < 1}<li class='{if $depth>0}-header{/if} {$liclass}'>{/if}
  52.             {if isset($node->children) && ($depth == 0)}
  53.                 <a  href="#" class="{$aclass}" id="nav-link-{$node->id}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  54.                     {$node->menutext} <span class="caret"></span>
  55.                 </a>
  56.                 <div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-link-{$node->id}">
  57.                     {Nav_menu data=$node->children depth=$depth+1}
  58.                 </div>
  59.             {else}
  60.                 <h6 class="dropdown-header">{$node->menutext}</h6>
  61.             {/if}
  62.             {if $depth < 1}</li>{/if}
  63.         {else if $node->type == 'separator'}
  64.             {if $depth < 1}<li role="separator" class='divider {$liclass}'></li>{/if}
  65.         {else}
  66.             {* regular item *}
  67.             {if $depth < 1}<li class="{$liclass}">{/if}
  68.             {if isset($node->children) && ($depth == 0)}
  69.                 <a  href="#" class="{$aclass}" id="nav-link-{$node->id}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  70.                     {$node->menutext} <span class="caret"></span>
  71.                 </a>
  72.                 <div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-link-{$node->id}">
  73.                     {Nav_menu data=$node->children depth=$depth+1}
  74.                 </div>
  75.             {else}
  76.                 <a class="{$aclass}" href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}><span>{$node->menutext}</span></a>
  77.             {/if}
  78.             {if $depth < 1}</li>{/if}
  79.         {/if}
  80.     {/foreach}
  81. {/strip}{/function}
  82.  
  83. {if $default_navbar_style=="default"}<div class="container">{/if}
  84.     <nav class="{$navbar_classes}">
  85.         {if $default_navbar_style!=="default"}<div class="container">{/if}
  86.         {if $navbar_toggler_align=="right"}
  87.         <a class="navbar-brand" href="#">
  88.             {CGSmartImage src=$navbar_brand alias1=navbar_logo} {$navbar_brand_text}
  89.         </a>
  90.         {/if}
  91.  
  92.         <button class="navbar-toggler navbar-toggler-right"
  93.                 type="button"
  94.                 data-toggle="collapse"
  95.                 data-target="#navbarCollapse"
  96.                 aria-controls="navbarCollapse"
  97.                 aria-expanded="false"
  98.                 aria-label="Toggle navigation">
  99.             {fa i=bars}
  100.         </button>
  101.  
  102.         {if $navbar_toggler_align=="left"}
  103.         <a class="navbar-brand" href="#">
  104.             {CGSmartImage src=$navbar_brand alias1=navbar_logo} {$navbar_brand_text}
  105.         </a>
  106.         {/if}
  107.  
  108.         <div class="collapse navbar-collapse" id="navbarCollapse">
  109.             <ul class="navbar-nav ml-auto">
  110.                 {if isset($nodes)}
  111.                     {Nav_menu data=$nodes depth=0}
  112.                 {/if}
  113.             </ul>
  114.         </div>
  115.     {if $default_navbar_style!=="default"}</div>{/if}
  116.     </nav>
  117. {if $default_navbar_style=="default"}</div>{/if}
Advertisement
Comments
  • PlymouthExpat
    9 days
    # text 0.23 KB | 0 0
    1. On line 51, this code is incomprehensible:
    2. {if $depth < 1}<li class='{if $depth>0}-header{/if} {$liclass}'>{/if}
    3. The conditional {if $depth>0} will never be true as it’s inside a contradictory conditional, so what is the point?
    • stom66
      9 days
      # text 0.23 KB | 0 0
      1. Lack of refactoring after numerous updates. Cmsms is dead so I have no reason to maintain this. If you're smart enough to find the fault you're smart enough to fix it if you need it, however your efforts would be better invested elsewhere.
      • PlymouthExpat
        9 days
        # text 0.18 KB | 0 0
        1. Why would you consider Cmsms to be ‘dead’? It seems to have gained a new enthusiasm from its developers, as far as I can see. Your offhand remark seems to me to be somewhat perfunctory!
        • stom66
          9 days (edited)
          # text 0.95 KB | 0 0
          1. My "offhand" remarks come from having used CMSMS for many years, and watching it stagnate. They are not "perfunctory" - they come from not wishing to see others waste their time where I have.
          2.  
          3. The CMSMS project has slowed considerably in development. Updates have often taken years. It is still not fully compatible with PHP 8. Large parts of the codebase and the plugin ecosystem were created by a developer that is no longer with the project. Those plugins are being slowly replaced rather than taken over. It has resulted in a very fragmented project. It lacks features, modern tooling, and is not likely to receive the substantial work required to modernise and upkeep development.
          4.  
          5. Use what you wish, but my advice is to focus your efforts on a more modern system rather than... Whatever you're doing with a template that hasn't been updated in 7 years, for an outdated release of bootstrap, running on a CMS that has been limping along for some time now.
          6.  
          7.  
          • PlymouthExpat
            9 days
            # text 0.31 KB | 0 0
            1. I would, then, suggest you remove your ‘resource’ from your website. If you’re not going to put any time into it, because you consider the system for which it was intended is not worth supporting, it might be doing others - who, like me, thought your work was worth using as a basis for a project - a favour!
            • stom66
              9 days
              # text 0.25 KB | 0 0
              1. I don't think anyone looking for a CMS these days would reasonably choose CMSMS, however the template may still be useful to those who are locked in to it. It functions - despite its minor logic error.
              2.  
              3. I would recommend you consider Bolt, Grav, or October.
              • PlymouthExpat
                8 days
                # text 0.71 KB | 1 0
                1. I am tied in to Cmsms and have been for some time; I'm not about to try and revamp my site having invested the time so far (although my successor as web manager might wish to do so). Having had another look at your own site, I see now where my confusion originated. You have a 'sectionheader' on the same level as the pages that come under that 'sectionheader' (so the 'sectionheader' title appears but isn't clickable), whereas the standard usage (in a default nav function) is to have a 'sectionheader' as a parent to children in a dropdown. I now understand where I need to modify your template to achieve my own objectives.
                2.  
                3. I will, nevertheless, take a look at your recommendations, out of interest at the very least 😊
                • stom66
                  8 days
                  # text 0.35 KB | 0 0
                  1. I can sympathize with that. I have a couple of large legacy sites that it is not viable to migrate. The slow development of cmsms has been incredibly frustrating, as well as the need to migrate to replacement modules after the departure of Calguy. The support for php8 is still tentative, so I have a server dedicated to the few sites that still require php7.
                  2.  
                  • PlymouthExpat
                    8 days
                    # text 0.33 KB | 0 0
                    1. I use a VPS running centos7, so am going to have to move to something else in the near future. For each of the domains I host on the VPS, I use a PHP version appropriate to the capability of the code (I can deploy anything from 7.2 to 8.3). A basic Cmsms site would function on PHP8.1, but not all 3rd party modules are compatible yet.
                    • stom66
                      8 days
                      # text 1.09 KB | 1 0
                      1. Snap! A lightsail instance running centos (converted to rocky) and virtualmin is how I'm hosting my CMSMS sites, but due to the security concerns of running Php 7 past EOL they're on their own instance.
                      2.  
                      3. These days I use Hugo for sites that don't require an admin interface, and either Grav or Bolt for sites that the customer needs to edit themselves.
                      4.  
                      5. CMSMS was the first CMS I ever used. It was great 10-15+ years ago, but it's so clunky compared to modern frameworks that I really dislike working with it. Even something as simple as abstracting a template to use with git means jumping through hoops and hoping someone doesn't click the wrong button in the admin panel.
                      6.  
                      7. Recently the Less/Sass plugin broke after a system update and it needed coaxing back to life. It reminded me how much I take for granted with other frameworks, and highlighted some of the missing functionality in CMSMS. For this and other reasons I'd encourage anyone who finds themselves in a similar position to migrate where feasible and to absolutely avoid using it for a new project.
                      8.  
                      9. Best of luck maintaining your cobwebsite!
Add Comment
Please, Sign In to add comment
Advertisement