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....


6

You can access children through the entry's descendants property. {# display event-information #} <ul> <li><a href="{{ entry.url }}">{{ entry.title }}</a> {# display subsections #} <ul> {% for subsection in entry.descendants %} <li><a href="{{ subsection.url }}">{{ ...


5

I think you need to set a conditional for the entry level for the parent, which is 1. {% set entries = craft.entries.section('pages') %} <ul id="nav"> {% nav entry in entries %} <li{% if entry.level == 1 %} class="whatever"{% endif %}> <a href="{{ entry.url }}">{{ entry.title }}</a> {% ifchildren %...


5

Ran into the same issues you had. Pulled this from a working site I recently built. Basically you have to get the topmost page. I found entry.getAncestors().level(1).first() works for that no matter what level you're in. From there, you just get everything that's underneath it. But first check to see if there's actually any children using {% if topLevel....


5

It appears the preferred way is by using getDescendants() — In fact, the children property is actually an alias for getDescendants(1). (The parameter specifies a maximum distance (i.e. number of levels) of the child from the parent.)


5

Another way to do this would be to assemble a list of the entry IDs that you want to look for a hero image in, in order, and then finding the first hero image related to one of those entries. To create that list of entry IDs, we start by creating an array of the current entry’s ID, and merge it with an array of the entry’s ancestors’ IDs in reverse order: {...


4

Disclaimer: I haven't ever used structure, but hopefully the method described below also works for that section type. You can do this quite easily with URL-segments Consider a URL like so: http://www.domain.com/section/entry/ http://www.domain.com/section/entry/subview-1 And so on. The section/entry route will hit your entry template, but you can ...


4

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 default the number of levels is not limited.) If you have entered at least one parent entry in your structure, you can assign child entries in two ways: 1 – When you ...


4

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"> <div class="col-24 gutter-bottom--half"> <h3>Available {{ entry.title }}</h3> {% for child in entry....


3

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 (ECM) is an important concept in Craft, because it's the driver for most content handling. Once you've got a bearing on what the ECM is, you can use it fairly ...


3

You need to get the parent entry model before requesting its children with the getChildren method. craft.entries.id(4) only creates a criteria model prepared to query for entries matching your criteria. You now have to use the first method to query for an entry model. {% set parent = craft.entries.id(4).first() %} {# Check if it indead returned an entry ...


3

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 parentIds = [3, 4, 5] %} {% set excludeIds = parentIds %} {% for parentId in parentIds %} {% set ids = craft.entries.descendantOf(parentId).ids() %} {% ...


3

Craft won't set the entry variable automatically unless the route matches a particular entry. If you're sharing a template between routes that may or may not correspond to an entry, you need to make sure that var gets set explicitly by you if not automatically by Craft: {% if entry is not defined %} {% set entry = craft.entries.section('myStructure')....


3

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 %} Have a look at the docs: https://craftcms.com/docs/templating/craft.categories#level


3

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: ['children', {order: 'postDate asc'}], }) %}


3

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 calculate the positions correctly in a clear way. So I would suggest you to use easy Craft methods. You could create an entries field to relate your children ...


3

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 parent entry is rendered in the "child" menu as well because otherwise you won't be able to access parent entries with children. It looks a bit overwhelming at ...


2

Try this: {{ entry.getChildren().total() }}


2

In addition to using the url segments as megatrond suggested. You can also define 'Entry Types', and use if..then conditionals or switch statements in your template to modify the layout or include different sub-templates, as required. {% if entry.type == 'project' %} {% include '/projects/_tabbed-entry' %} {% endif %} Furthermore you can use levels and ...


2

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 / more robust functionality added to the Craft system in the future, please upvote this feature request: https://github.com/craftcms/cms/issues/1628


2

Sounds like a feature request for maximum number of levels in a structure. But had a thought about this. Since structures have a level parameter, you could make a simple plugin to more or less restrict the number of levels you can have a structure. If it's more than 1, then set the page's parent to the top most parent, effectively limiting it to have that ...


2

Something like this should do the trick! You want to get all the section parent entries, then search for child entries that are related to the category you want. {% set parents = craft.entries.section('your_structure_handle').level(1) %} {% for parent in parents %} {% set children = craft.entries.decendantOf(parent).relatedTo(category) %} {% if ...


2

If you want all the descendent too you can use: {% set totalDescendents = entry.getDescendants().count() %} https://buildwithcraft.com/docs/templating/entrymodel#getDescendants


2

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 drastic change to how cache busting works. As a workaround, you can change your descendantOf param value to currentPage.id rather than just currentPage.


2

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).)


2

Because the descendantOf function expects a parameter of type ElementInterface or an integer /** * Sets the [[descendantOf]] property. * * @param int|ElementInterface|null $value The property value * * @return static self reference */ public function descendantOf($value); You'll have to insert the ID of your accessories element or the element itself ...


2

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/{slug}{% else %}{parent.slug}/{slug}{% endif %} For your templating question, if you want a different template for parents and children, you need an if ...


2

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 limit your result to only elements with a level greater than 1 .level('>1') and list. {% set pages = craft.entries.slug('slug-of-first-parent').one()....


2

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').level(1).status('live') %} First of all, store the elements of the slug in an array: {% set slugs = craft.request.segments %} Here is the first for-loop for the ...


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