42

The cleanest way I have found to achieve this is to create a generic template for the structure as well as a custom template for each entry that needs one, ensuring that its path matches the entry's uri. I then put this single line of code in the structure's selected template and it works beautifully: {% extends [entry.uri, '_generic'] %} This should ...


32

This isn't documented, so it's subject to change: When you set a Single to be the homepage, its slug is automatically set to __home__. If you want your homepage to be part of a Structure, rather than a separate Single, you can set the slug of a Structure entry to __home__, which makes it act as the site's homepage and gives it that little Home icon in ...


22

Have you switched sorting to "Structure"? When you're not sorting by Structure, you won't be able to rearrange the entries.


17

A recursive macro will help you get around the limitations of ifchildren (which P&T will hopefully resolve soon), as follows: {% set mainEntry = craft.entries.slug(craft.request.getSegment(1)).first() %} {% set subnav = craft.entries.descendantOf(mainEntry).level(2) %} {% macro recursiveChildren(page) %} {% if page.hasDescendants and page.slug == ...


14

The "this is for the homepage" button available on single sections does two things for you, when you navigate to the home page's URL: it populates the entry variable with the single's entry model it loads the template spezified in the single's CP settings . Actually nothing you can't do manually with your home page's index.html: {# Replace the default `...


13

Got it! {% if craft.request.segments %} <nav class="breadcrubs"> <div class="container"> <div class="row"> <ol class="breadcrumb"> <li><a href="{{ siteUrl }}">Home</a></li> {% for crumb in entry.getAncestors() %} <li>{{ crumb....


12

Structure for "sorting-only" I haven't tried the approach that you are thinking of yet, but your concerns regarding the query count are not that unfounded. You would need to use the relatedTo() parameter with the ElementCriteriaModel you create on your pages (to get the single's content) on your navigation include (even if you only want to get the entries ...


12

If you need to get the level 2 children for a specific Structure entry, and you have that entry's EntryModel (i.e. you have an entry variable which refers to the Structure entry), you can just use the EntryModel's children property, appending level to only pull children from the desired level: {% set children = entry.children().level(2) %} There's also a ...


11

The primary parameter you're looking for is lft: craft.entries.section('volumes').order('lft desc')


11

I don't know if its possible to be much clearer than the official docs on this matter, but basically a Structure is needed if your entries needs to be in a specific order (and you want to manage that order w/ an easy to use, drag-n-drop interface within the Control Panel), or if they need to be nested (i.e. hierarchical, with parent/child entries). The ...


9

I recently setup a structure which contains (almost) every page of my site. When I set it up, I specified only {slug} as the URL. So far, it's working fantastically! And that's with about 30-40 pages created in the structure (some nested within others).


9

Set the Nested Entries URL format to: {parent.uri}/{slug}


9

TL;DR: Let the content dictate how you model and architect it. If the site is sufficiently small or sufficiently simple, I think either approach is ok. My team has used both approaches, and it really depends on the Client's needs. An incomplete list of reasons to use separate channels and structures are: Tagging/Categorizing things like Products is ...


8

The Methods section on the EntryModel documentation page has a lot of useful things for working with navigation for Structure sections. You can use hasDescendants(): {% if entry.hasDescendants() %}class="has-dropdown"{% endif %}


8

There may be a better option, but off the top of my head, you could do: {% set countParent = craft.entries.slug('oakview-hotel').first() %} {% set count = craft.entries.section('hotelDetails').descendantOf(countParent).level(3).type('review').total() %} {{ count }}


8

Ordering and Hierarchy are the main benefits but they create a couple of side benefits such as the ability to get the "children" and "parents" of an entry get siblings including next and previous siblings The best part is there no real downside, they have all the features and functions of a regular channel PLUS the structure.


8

You could try using use the reverse twig filter. {% for entry in craft.entries.section('volumes')|reverse %} ... {% endfor %}


8

A little bit late but here it is. Go to https://pluginfactory.io/ and create a plugin, you need at least 1 Controller but you can leave the Name value blank to create a controller with the same Name as your PluginHandle. So if you choose "Experiment" as your Pluginhandle your controller will be ExperimentController Click on "Build my Plugin" and save the ...


8

You can insert an array of different sections instead of a single one to pull entries from multiple sections {% set entries = craft.entries.section(['sectionHandle', 'sectionHandleTwo']).limit(10) %} You can also write that {% set entries = craft.entries({ section: ['sectionHandle', 'sectionHandleTwo'], limit: 10 }) %} If you remove the .section() / ...


7

Craft provides many helpful methods to traverse structure sections and your use case is no exception. Instead of using .getPrev() or .getNext(), try .getPrevSibling() or .getNextSibling() (or their aliases .prevSibling and .nextSibling.) You could create prev/next links with something like this: {% set prev = entry.prevSibling %} {% if prev %} <a ...


7

Actually your code should work just fine. But by default only 100 entries are fetched, maybe you need to increase the limit: {% set entries = craft.entries.section().limit(null) %} But if you just want to create a Sitemap, try Ben Croker's Sitemap-Plugin (I really like it)


7

I'm not sure if you can set a default entry type within Craft. But a reasonably workaround would be to go to Settings > Sections, then click 'Edit entry types' for the section you need to apply this to. Next, drag the entry type you would like to be used by default to the top of the entry-type list. That way, when a new entry is added to the Section, the ...


7

getAncestors() gets all entries that are ancestors. Since you're looping through them what rootEntry is set to last time through is the closest ancestor. You can avoid the loop and just get the first one: {% set rootEntry = entry.getAncestors().first() %}


7

Craft 2.6.2789 added this feature, which is seems you've reverse engineered. :) It is now possible to eager-load Structure entries' and categories' descendants using the 'descendants' handle.


7

You basically have two options for creating a "listing" or "archive" view for your Channel or Structure sections. The first option is to create a Single. This is in many cases appropriate, e.g. if you need to add content to the listing view in addition to the actual entry list, such as a visual banner, introductory text etc. Inside the Single section's ...


6

What about using CSS for your numbers? (Yes, this answer makes your question sound a bit off-topic, sorry for that, hehe) Mainmenu: .mainNav { counter-reset: mainNav; } .mainNav-item { counter-increment: mainNav; } .mainNav-item::before { content: counter(mainNav) ". "; } Submenu (double digits): .subNav { counter-reset: subNav; } .subNav-item { ...


6

A structure is a section that allows for a 'tree' like layout with hierarchy. A good example of where Structures might be used for instance is the Craft documentation pages, or building a navigation using a section.


6

This could be achieved through a recursive macro: {% macro recursive_nav(entries, depth) %} {% import _self as self %} <ul> {% for e in entries %} <li> <a href="{{ e.url }}">{{ e.title }}</a> {% if e.hasDescendants() %} {{ self.recursive_nav(e.children, depth+1) }} {% ...


6

Craft's built-in {% nav %} tag would save you having to write your own recursive macro: Adapted from http://buildwithcraft.com/docs/templating/nav <div class="panel"> <h2>People</h2> <ul> {% nav entry in craft.entries.section('people') %} <li> <a href="{{ entry.url }}">{{ entry....


6

You can get your entry's parent entry with getParent(). Use this entry method in a conditional, if your entry has no hero image set. You can nest the code to climb up all of your structure's levels: {# Check if entry has hero image #} {% if entry.hero.first() %} {{ entry.hero.first().url }} {% else %} {# Check the parent entry #} {% if entry....


Only top voted, non community-wiki answers of a minimum length are eligible