As some of you may have seen I've been asking on here and on Slack regarding the best way to go about creating a navigation on a site.
As yet, nothing I have tried is working and any code that I've been given to try also hasn't worked. (Thanks to everyone who has given code so far though).
Therefore I have literally stripped down everything in the hope that someone might be able to tell me where I'm going wrong as I'm sure that something as simple as this shouldn't be as difficult.
I have a completely fresh install of Craft 2 with the standard templates that come with Craft and I have then created a Structure called (creatively enough) Navigation of which the hierarchy can be seen below.
Home
Services
---- Service 1
---- Service 2
--------- Sub Service 1
---- Service 3
Galleries
---- Gallery 1
---- Gallery 2
............
The above is actually just an example but reflects the sort of items that could go into the site.
Any of the items above could also be either an entry, a single or a template that has a channel on it and so on and so forth.
First up I'm not sure if I actually need to place any information into the Entry URL Format and Entry Template settings for the section as I'm guessing these aren't maybe all that important as the section is literally just being used for creating navigation on the site. That said I did fill them out with standard information just in case.
Next on the standard news/_entry.html template I placed this code :
{% set pages = craft.entries.section('navigation') %}
<nav>
<ul>
{% nav page in pages %}
<li>
{{ page.getLink() }}
{% ifchildren %}
<ul>
{% children %}
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
</nav>
This allows me to spit out the entire navigation which is good so far but in my Structure section I have an Entries field which allows me to choose an entry. I first of all have no idea of how to spit out this as the link instead of the {{ page.getLink() }}
code above.
My Entries field is called singleEntrySelector and I tried {{ page.singleEntrySelector }}
to see if it would spit anything out but that didn't work and I got an error on the page.
So I'm wondering how do I go about spitting out the content of the singleEntrySelector field so that my navigation items can point to the correct URL?
Once that is working I'd like to have it so that when I'm on say Sub Service 1 that I can create a secondary navigation on the page which will show me everything from Services down to (in this example) Service 3 so pretty much a very standard secondary navigation output.
That should (I'm hoping) allow me to do what I need here although I am definitely open to other ways of approaching this if I'm completely seeing things wrong here?
Many thanks,
Mark
P.S. I'd also like to be able to in the end spit out the navigation using whatever HTML code I need to as I will be utilising this on a responsive site and so have no idea yet as to what code I will need to encapsulate it all in. Therefore if the {% nav %}
tag isn't the right fit here in that it won't allow me to do that then I'd really appreciate being shown how to spit it out in some other way that will allow me to do just that.