Skip to main content
23 votes
Accepted

Get children from a Structure entry

If you need to get the level 2 children for a specific parent entry, and you have that entry's entry model instance (i.e. you have an entry variable, referring to the parent entry), you can use that ...
Mats Mikkel Rummelhoff's user avatar
14 votes
Accepted

How to fetch entries from multiple sections

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) %} ...
Robin Schambach's user avatar
9 votes
Accepted

One structure vs a structure per section?

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 ...
Ian DeRanieri's user avatar
9 votes

Nested Entries in Craft 3

I kind of found a work around, but doesn't seem like it's the correct way to be doing this. {parent.uri ? parent.uri : 'static'}/{slug}
Kenyon Kowal's user avatar
8 votes
Accepted

Entry Form - Multiple Entries & Entry Type & Parent

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 ...
Robin Schambach's user avatar
7 votes
Accepted

Eager Loading a Structure and descendants

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.
Brad Bell's user avatar
  • 67.5k
7 votes
Accepted

Ordering of products?

Product types are really all about data concerns - so if the data you're storing for your canines/equines (hereafter known as dogs and horses to save some typing ;) ) - is the same, then you're right ...
Jeremy Daalder's user avatar
7 votes

Best practice for channels and structures

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 ...
Mats Mikkel Rummelhoff's user avatar
6 votes
Accepted

URL structure for structure section

If you do this: {parent.uri}/{slug} You should get URLs like this: site.com/parent site.com/parent/child-1 site.com/parent/child-2 Does that make sense?
4midori's user avatar
  • 656
5 votes

Order/sort a structure section by date too?

This should work {% set entries = craft.entries({ section: 'news', sortOrder: 'postDate desc, lft asc', }) %}
carlcs's user avatar
  • 36.3k
5 votes
Accepted

Recommended Structure - One Site with Pages With Totally Different Layouts?

Option 1 is a safe bet. This allows you to have completely separate, editable templates for each chosen year. You can then change the page slug to match the year of that page. You can reuse fields ...
mrtpain's user avatar
  • 176
5 votes
Accepted

Product Categories, Structures and Channels

Typically, I will create a single for each product "home" page, and then a channel for my products or sub-pages. I will generally use a channel vs. a structure unless I know I want to manually control ...
Damon's user avatar
  • 4,706
4 votes

Add home page to a structure?

From an IA and content-modelling perspective, putting all your site's "pages" in a Structure is fraught with problems, and, in my opinion, does a terrible disservice to the future-friendly approach ...
James Smith's user avatar
  • 5,344
4 votes
Accepted

Are categories the best way to organize Commerce product filters?

Hard to say if they're the 'best' tool, but I don't see anything here you can't do with Craft categories and they seem the logical and built in way to go about it. In essence you simply look at your ...
Jeremy Daalder's user avatar
4 votes
Accepted

Reusing logic to set string variables

I would use macros. A Twig macro is basically a function, that can take arguments and render HTML. Macros can be defined inline (i.e. in the same template where it's used) or in a separate file (...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

How to prevent select user groups from reordering structures

You should be able to ensure that the elements aren't moved by using the structures.onBeforeMoveElement hook in a plugin: public function init() { craft()->on('structures.beforeMoveElement', ...
Mike Pepper's user avatar
  • 4,391
4 votes
Accepted

How to manage different templates for a structure

Your approach looks good to me. There are different ways you can make it happen: If you set up your structure in the CP you can decide how many levels you want to allow for that structure. (By ...
Wolfram Gehring's user avatar
4 votes
Accepted

How can I display second level children only from a specific parent structure item?

yes you can! You may search for a slug craft.entries.slug('slug-of-first-parent'), select the first result .one(), and then the children by .getChildren(). Now you can proceed as you already did and ...
Luke's user avatar
  • 531
3 votes
Accepted

How do I check if a structure has any entries at level 3 when I'm at level 1?

To make it works I had to query in the section for descendant entries at level 3 of a current entry variable. {% set products = craft.entries.section('products') %} {% if lvl == 1 and products....
Dominik Krulak's user avatar
3 votes
Accepted

How to setup the structure in Craft for a Property Development site I'm building

I think I follow where you are going. It sounds like you have a few levels so you will indeed be working with a structure (instead of a channel or single). I'm not sure what "All Developments" means -...
Damon's user avatar
  • 4,706
3 votes

How to prevent select user groups from reordering structures

Impossible out of the box – there's no permission setting for ordering Structures. For now, I'd add a feature request and hack it in. The easiest solution is probably to use the CP Body Classes and ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Hiding Field on Parent Entry

You can create two different Entry Types for your Structure section, and use one Entry Type for parent entries, and a different entry type for child entries. Entry Types have their own field layout, ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Get structure url

I think you've made this more complicated that it needs to be for yourself. Reading the Craft docs on Outputting the Entry’s Ancestors in a Structure Section it looks like you can use the handle ....
Luke Pearce's user avatar
  • 3,863
3 votes
Accepted

Only fetch structure entries that are first level or sub level that don't have a parent

You can use the hasDescendants() method to filter out any parent entry with children. You have to use an ElementCriteriaModel with .getPrev() and .getNext(). {% set entries = craft.entries.section( '...
Luke Pearce's user avatar
  • 3,863
3 votes
Accepted

Redirect to another EntryType template if no Children exist

Fixed! So bearing in mind i'm using this method to load templates according to entry type, Clive Portman's answer got me thinking about hasDescendants. In my _entry.html I now have something like ...
Martin's user avatar
  • 1,203
3 votes
Accepted

Why isn't relatedTo not working (anymore)?

You are so close! All you need to do is to remove the ’.slug’, because that is what the param is expecting.
carlcs's user avatar
  • 36.3k
3 votes
Accepted

Start a Loop at the nth Entry in a Structure and Loop to the End?

Using the offset parameter you can achieve this: {% for entry in craft.entries.section('structureSection').offset(8) %}
Siebird's user avatar
  • 373
3 votes
Accepted

Eager-Loading child elements in a multi-level structure section

To use eager-loading for the child elements add 'children' to the with parameter. {% set mice = craft.entries({ section: 'experiments', level: 3, descendantOf: entry.id, with: ['...
carlcs's user avatar
  • 36.3k
3 votes

How can I create a family tree hierarchy in Craft?

I can't think of an easy and clean way to visualize this kind of structure in a default list. So if you want to be able to display the structure from your diagram dynamically you'll have much work to ...
Robin Schambach's user avatar
3 votes
Accepted

Why is the parent slug showing up in the child slug in a structure?

Pretty sure that the ResaveElements task just hadn't run yet - my queue was stuck. Once I cleared the stuck items, the issue resolved on its own!
Katie Fritz's user avatar

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