Hot answers tagged

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


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


3

You need to use newParentId: $navigationItem = new Entry(); $navigationItem->typeId = 4; $navigationItem->sectionId = $navigationSection->id; $navigationItem->title = $entry->title; $navigationItem->newParentId = $herbsNavigationEntry->id; $navigationItem->setFieldValue('navLink', '/tags/' . $entry->slug); if (!Craft::$app->...


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

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

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

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

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

Edit your section‘s settings (Settings > Sections > [Section Name]), and delete the static/ from the Entry URI Format.


2

After much help and direction form @RobinSchambach (much appreciated). I have resolved this as follows; {% set currentPage = craft.entries.section('pages').slug('archive').first() %} {% set currentAncestors = currentPage.getAncestors.find() %} {% set crumbs = currentAncestors|merge([currentPage]) %} {% if entry is defined and entry.section.handle != '...


2

As @Robin Schambach said, you need to loop through the ancestors. {% set parent = craft.entries.section('pages').slug('phone-directory') %} {% for ancestor in parent.getAncestors() %} {{ ancestor.title }} {% endfor %} This won't output the Phone Directory entry since you're just looping through its ancestors. So to complete the breadcrumbs you'll need ...


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


1

Try merging like this {% set parent = craft.entries.section('pages').id(8) %} {% set entries = craft.entries.section('pages').descendantOf(8).limit(1) %} {% set entries = parent|merge(entries) %} {% for entry in entries.all() %} output your entries here {% endfor %}


1

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 and the child <li>. <ul class="Navigation"> {# Get top-level entries in structure section 'features' #} {% set parentFeatures = craft.entries....


1

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 children as needed.


1

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) ? entry : entry.getAncestors().level(2).first() %} {% if navList.hasDescendants %} <ul> {% set nav = navList.getDescendants() %} &...


1

This is commonly called 'reverse-related entries' and is achievable using relatedTo(). See here for some info... My question is if I chose to show the entry selected on a new page how would I show the relationship to the page it appears on / came from? Perhaps as a title from the previous page or a back button. For example, if a visitor were on an Audio ...


1

It's possible I'm misunderstanding, but aren't you just looking for a Structure Section? It's like a Channel except that it allows for both order and hierarchy.


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