6 votes

Check if child entries exists

If I figured out correctly what you want to do - this should do the trick: {% if entry.children | length %} <div class="section bg-pattern"> <div class="inner"> ...
Krzysztof Boduch's user avatar
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
  • 521
3 votes
Accepted

Craft CMS Structure: How can I display parent and child items on an active parent page?

I hope I have understand your problem.. Let's look at your code: One sidenote: It might be good to limit your pages-selection only to active pages: {% set pages = craft.entries.section('about')....
Luke's user avatar
  • 521
3 votes
Accepted

How do I create a structure side navigation that will show active parent list-item and active child list-item

After a long search and lots of trial and error, I've found the perfect solution! This is how I created a dynamic structure navigation : parent/child (2 levels deep) with class="active" on the parent ...
mateostabio's user avatar
3 votes
Accepted

How do I get different URL Format with parent/child structures & how do I display different templates?

To get different URL Format for parent & child pages, you need to go to the CP structure settings and edit the Entry URI Format. This is how your URI should look like: {% if level == 1 %}features/...
mateostabio's user avatar
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

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.2k
3 votes

How to target Sub-Category of Sub-Category

I'm not sure, but I think you might need to use level in your loop. {% set categories = craft.categories.group('groupHandle').level(3) %} {% for category in categories %} // etc {% endfor %} ...
Ryan's user avatar
  • 1,952
3 votes
Accepted

How do I hide children of a disabled parent in a nav?

This is an example of our "quick and dirty" menu macro we used in older projects. It's recursive so it can have as many levels as you want and will only fetch enabled entries. For mobile devices the ...
Robin Schambach's user avatar
3 votes
Accepted

How can I get an entry's child category, and not the parent category?

Your Categories field (entry.chooseLocation) is an Element Criteria Model. It's exactly the same as if you'd done something like this... craft.categories.group('myGroup') The Element Criteria Model (...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

Exclude certain entries and its children from navigation

If it’s true that the descendantOf param doesn’t allow to pass in multiple entries, you probably need to work around that issue and grab the descendants for each parent entry individually. {% set ...
carlcs's user avatar
  • 36.2k
2 votes
Accepted

Newly added child entries not showing on listing/parent page straight away

This is a known issue – automatic cache busting currently doesn’t work when the descendantOf param is set to an actual element. Unfortunately there’s no easy fix on Craft’s end, without a pretty ...
Brandon Kelly's user avatar
2 votes
Accepted

How to get first child URL within Craft/Twig Nav tags

In that case you can put this in the href value: {{ entry.descendants.type('page').first.url ?? '' }} (Replace page with the other entry type handle(s).)
Brandon Kelly's user avatar
2 votes
Accepted

Show only children relative to current page

Don't use the nav tag. Assuming a structure called pages, try something like this: {% set pages = craft.entries.section('pages').level(1).all() %} <ul> {% for page in pages %} <li> ...
Oli's user avatar
  • 7,495
2 votes
Accepted

Get category children

Because the descendantOf function expects a parameter of type ElementInterface or an integer /** * Sets the [[descendantOf]] property. * * @param int|ElementInterface|null $value The property ...
Robin Schambach's user avatar
2 votes

Structure Entry Item's Parent

For very simple use cases, I've created a plugin that adds some validation to enforce this type of hierarchy: https://github.com/jordanlev/craft-EnforceDualHierarchy If you'd like to see better / ...
Jordan Lev's user avatar
2 votes

Asset has a child category but only displays the parent on templates

It seems that setting a child category also sets it's parents categories too (top level being first, and selected child category is last). Able to get the category with {{ asset.categoryField.all()|...
Jaytrix's user avatar
  • 187
1 vote

Delete Parent and Children via the frontend

Many of those advanced endpoints are undocumented, but you can find out a lot with the devtools. If you use the Delete (with Descendants) option in the backend and check the devtools, you can see it ...
MoritzLost's user avatar
  • 11.3k
1 vote
Accepted

Change the URL of nav child entry conditionally

Instead of using {% ifchildren %} use {% if entry.hasDescendants %}. It allows for more flexibility in your nav templating.
Simon Kuran's user avatar
  • 3,015
1 vote

Craft 2, child dropdown, database

If I understand correctly, you want to create a <select> element with options from fields you already setup in the CMS. In that case you can use something like this to get the data for the field:...
Seth Warburton's user avatar
1 vote

How do I hide children of a disabled parent in a nav?

Try wrapping the {% ifchildren %} block with this {% if page.enabled %}. Full example. {% nav page in craft.entries.section('pages') %} <li> <a href="{{ page.url }}">{{ page.title }}&...
martisj's user avatar
  • 11
1 vote

How can I create a family tree hierarchy in Craft?

Create a regular channel where the entries have a relationship to the parent and not the child. That means that each child can have any number of parents and each parent can be related to as many ...
foamcow's user avatar
  • 2,019
1 vote

Newly added child entries not showing on listing/parent page straight away

I found a better solution. I'm using the CacheFlag plugin which solves this problem. And it's very easy to add to existing code.
Tom De Smet's user avatar
  • 1,456
1 vote

Newly added child entries not showing on listing/parent page straight away

Since using descendantOf(currentPage.id), as Brandon suggested, didn't work, I have come up with this workaround solution: {% set currentPageID = entry.id %} {% set entries = craft.entries.type('...
Katrin's user avatar
  • 674
1 vote

Counting included child blocks in the Neo plugin

The answer by Tom Bauer given to my question here should be of help. You're not far off. You need to set a variable and count the blocks in your neo loop. Then use if statements in the loop depending ...
lucaslink's user avatar
1 vote

List both parent entry and its child entry

This is the corrected Twig code. I simply added {{ entry.title }} as an <li> item. This nav appears only on the page that I needed entry.title displaying. {% set navList = (entry.level == 2) ? ...
Steve Davies's user avatar
1 vote
Accepted

Check if child entries exists

Found a solution, I needed: {% if entry.hasDescendants() %} {% if entry.hasDescendants() %} <div class="section bg-pattern"> <div class="inner"> <div class="...
sarah3585's user avatar
  • 899
1 vote
Accepted

Display children's order numbers

If you're getting all the descendants in the for loop, you can use loop to get the index of the current iteration: {% for chapter in entry.descendants %} <div class="part"><span>Part {...
André Elvan's user avatar
  • 7,288
1 vote

Show only children of current page in submenu

quite similar solution with the one function, first function fails with following error : Calling unknown method: craft\elements\db\EntryQuery::first() {% set rootEntry = entry.ancestors.level(1).one(...
erwanpia's user avatar

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