am-impact / amnav

Navigation plugin for Craft
168 stars 20 forks source link

Best practice to allow users to include a menu on a particular entry. #33

Closed adamazing closed 9 years ago

adamazing commented 9 years ago

I had setup a Craft site with the navigation menus hard-coded/overridden in the relevant templates, e.g.:

{% block internalSidebar %}
    {{ craft.amNav.getNav("commercialSideMenu") }}
{% endblock %}

...with the user being able to edit existing menus in the back-end as required.

Is there a(n easy) way to specify a "Menu" field type for an entry such that a user could add a navigation menu by selecting it from the list of available menus? Thanks, Adam

adamazing commented 9 years ago

In concert with craft-lj-dynamicfields I was able to easily get this working with only a small change: exposing getNavigations(). E.g.:

{% for nav in craft.amNav.getNavigations() %}
    { "value": "{{ nav.handle }}", "label":"{{ nav.name }}" }
    {% if not loop.last %},{% endif %}
{% endfor %}

Create a dynamic dropdown field called (e.g.) "Menu select" and paste the twig code above under "Dropdown Options": image

hubertprein commented 9 years ago

There's a fieldtype in the plugin to add entries to an existing navigation, but there's indeed no fieldtype for chosing a navigation to be displayed on a page.

I never saw the use for creating a fieldtype where a client could choose a navigation to pop up somewhere. You'd really just hardcode it where it should pop up. If a fieldtype should be made for this, then there should be fieldtype options as well. Since you're going to miss parameters that are available when outputting a navigation.

If you don't mind me asking, what's your use case scenario for needing this fieldtype?

adamazing commented 9 years ago

Hey Hubert, Thanks for the response. We really just need our (non-technical) client to be able to create custom navigation menus for something like "Related Links" and pick which menu they want to use in a defined spot in the layout on a per entry basis and we want them to be able to do that themselves. Not all pages may require a menu in this spot and different pages within a structure may need to have different menus

I'm happy to stick with the solution I've got now as it Works For Me. With the current hack, (exposing getNavigations and using lj-dynamicfields to create a dynamic dropdown containing navigation menu handles) our users are just going to be specifying the navigation menu and we're still maintaining control over the output in the templates.

Does that make sense? (Have I completely overcomplicated things?)

Thanks, Adam

On 7 May 2015 at 01:57, Hubert Prein notifications@github.com wrote:

There's a fieldtype in the plugin to add entries to an existing navigation, but there's indeed no fieldtype for chosing a navigation to be displayed on a page.

I never saw the use for creating a fieldtype where a client could choose a navigation to pop up somewhere. You'd really just hardcode it where it should pop up. If a fieldtype should be made for this, then there should be fieldtype options as well. Since you're going to miss parameters that are available when outputting a navigation.

If you don't mind me asking, what's your use case scenario for needing this fieldtype?

— Reply to this email directly or view it on GitHub https://github.com/am-impact/amnav/issues/33#issuecomment-99473002.

hubertprein commented 9 years ago

@adamazing Crystal clear.

Added a field type for you in the latest release.