Comments (18)
I did a short test. To get all 2 level elements inside the navigation you can use the following snipped inside the index.twig from the NavigationMain Component:
<nav class="flyntComponent" is="flynt-navigation-main">
<div class="wrapper">
<div class="container centerMaxWidthContainer">
<a class="logo" href="{{ site.link }}">
<div class="logo-site-name">{{ site.name|trim }}</div>
<div class="logo-site-description">{{ site.description|trim }}</div>
</a>
{% if menu %}
<ul class="menu">
{% for item in menu.items %}
<li class="menu-item {{ item.current ? 'menu-item--current' }}">
<a class="menu-link" href="{{ item.link }}" {{ item.target == '_blank' ? 'target="_blank" rel="noopener noreferrer"' }}>{{ item.title }}</a>
{# Simple 2 level navigation start #}
{% if item.get_children %}
<ul class="menu menu-submenu">
{% for item in item.get_children %}
<li class="menu-item {{ item.current ? 'menu-item--current' }}">
<a class="menu-link" href="{{ item.link }}" {{ item.target == '_blank' ? 'target="_blank" rel="noopener noreferrer"' }}>{{ item.title }}</a>
</li>
</ul>
{% endfor %}
{% endif %}
{# Simple 2 level navigation end #}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</nav>
Note: This code snipped doesn’t support deeper navigation levels.
I hope this helps.
from flynt.
I think, the main navigation doesn’t support dropdown items, out-of-the-box and at the moment. But with some customization into the navigation components it shouldn’t something big.
from flynt.
The issue I'm having is that the sub menu (level--1) does not render.
Here is my index.twig file in the Navigation Main folder:
<nav is="flynt-navigation-main" class="flyntComponent">
<div class="wrapper">
<div class="container centerMaxWidthContainer">
<a class="logo" href="{{ site.link }}">
<img class="logo-image" src="{{ logo.src }}" alt="project-logo">
</a>
{% if menu %}
<nav class="navigation">
{% include 'menu.twig' with { 'items': menu.get_items, 'level': '0', 'maxLevel': maxLevel } only %}
</nav>
{% endif %}
{% if contentHtml %}
<div class="content">{{ contentHtml|e('wp_kses_post') }}</div>
{% endif %}
</div>
</div>
</nav>
Here is my include menu.twig file in the Navigation Main:
<ul class="menu menu--level-{{ level }}">
{% for item in items %}
{% set hasChildren = item.get_children is defined and item.get_children|length > 0 %}
<li class="{{ item.classes | join(' ') }}">
<a class="menu-link" href="{{ item.link }}"{% if item.target %} target="{{ item.target }}"{% endif %}>{{ item.title }}</a>
{% if hasChildren %}
<p>Yes has children</p>
<ul class="menu menu--level-1">
<li class="{{ item.classes | join(' ') }}">
<a class="menu-link" href="{{ item.link }}"{% if item.target %} target="{{ item.target }}"{% endif %}>
{{ item.title }} Contact Us</a></li>
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
The top level menu works fine. When the main menu has children, {% if hasChildren %) is true. However the sub menu does not appear and the top level menu is repeated. See below for the rendered html:
<nav class="navigation">
<ul class="menu menu--level-0">
<li class=" menu-item menu-item-type-post_type menu-item-object-page menu-item-29 menu-item-has-children">
<a class="menu-link" href="//localhost:3000/wordpress/about/">About Us</a>
<p>Yes has children</p>
<ul class="menu menu--level-1">
<li class=" menu-item menu-item-type-post_type menu-item-object-page menu-item-29 menu-item-has-children">
<a class="menu-link" href="//localhost:3000/wordpress/about/">
About Us </a></li>[note: top level nav repeats - no sub menu]
</ul>
</li>
Any help debugging would be appreciated.
from flynt.
@purchasingtoolpak On second level you are still in the {% for item in items %}
loop. item
is still the first level, second level array lives under item.get_children
or item.children
not item
. Can you try another loop into item.get_children
?
Also dumping/printing your data (either twig or in your functions.php
) can be helpful when dealing with issues like this to have an overview of where is what. :)
from flynt.
OK, only need 2 levels and this is working great. If you could share the _style.scss that would be appreciated.
THANKS
from flynt.
@purchasingtoolpak, great to hear that the navigation is working.
There a many ways to style a menu with SCSS and you did not wrote anything about what kind of styles you like to implement.
If you send me an example, I'll see what I can do for you.
And keep in mind that the next step after customizing the main navigation is usually to adjust the mobile navigation ;)
from flynt.
No further concerns here. It would be great if flynt came out of the box with a multi-level menu. Most WordPress themes seem to support. Thanks for all the help on this pixelsaft!
from flynt.
@purchasingtoolpak Thanks for your feedback. We're considering to extend the navigation to support multiple levels. In the past, we noticed that there are many different concepts to a multi-level navigation and thus wanted to keep it simple, instead of committing to one specific case.
from flynt.
Please excuse me for opening this after almost a year.
May I ask @timohubois - is your snippet still relevant for v1.4.?
Using your code I am able to bring in the sub menu items, but the styling of the children loop is so off I'm wondering if there was an update.
from flynt.
@CodeConvergence by default there is no default styling for a dropdown submenu built in, so that you can style very flexible for your needs.
from flynt.
@timohubois
Hi Timo,
Thanks for the quick response. Knowing that it is only a styling issue helps.
Maybe, if components are shared as proposed in Sharing Components #377, then a dropdown may become available, as a starter at least, for those who would like to use it.
from flynt.
from flynt.
Hi Dave,
Thank you! I really like the menu you are using on thearcofhr.org, sharing something like that would (imho) be great for anyone getting started with Flynt. I’m using TailwindCSS, perhaps seeing the way you’ve used Bulma will allow me to do the same with TW or just plain CSS.
May I email you at purchase… ?
from flynt.
from flynt.
Thanks so much!
from flynt.
Quick feedback: Your component works perfectly and implementation was a breeze :)
Bulma’s Sass foundation is a good fit with Flynt, so customization was smooth sailing.
Would you be willing to share your mobile navigation component too?
Thanks again!
from flynt.
from flynt.
Thank you so much Dave!
from flynt.
Related Issues (20)
- Issue: npm install errors and warnings HOT 3
- Custom Function function 'n' not found or invalid function name HOT 1
- Trying to dynamically load a slider package, only if required HOT 1
- Unable to install NPM HOT 2
- composer install not working twig/cache-extension is abandoned HOT 15
- How to link scripts correctly HOT 4
- How to implement conditional_logic? HOT 2
- Local Environment (Flynt Next) HOT 2
- Is there a good way to bulk create posts with components? HOT 1
- Minor front and back end issues HOT 4
- Not Getting meta data in GridPostsLatest HOT 6
- Can it be used with a hosted wordpress with limited ssh? HOT 1
- Build Fails HOT 3
- similar build issue on Windows HOT 6
- How to use repo within docker containers - DDEV HOT 6
- Migration Guide HOT 1
- How to add tailwind? HOT 1
- Can't access development site from external device
- How can we call the shortcodes in flynt ? HOT 1
- Flynt v2.1: Cannot correctly save ACF Field Groups HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flynt.