11 votes
Accepted

Loading javascript on specific sections/pages

A safe way to add JavaScript resources via the frontend, is to use the {% includeJsFile %} Twig function in your template. The nice thing about the includeJsFile function is that it doesn't matter ...
Mats Mikkel Rummelhoff's user avatar
6 votes

Modelling flexible content sections and recommendations

I'm not familiar with ACF, but if you're looking for blocks-within-blocks, you could use the Neo plugin/fieldType. It allows you to define blocks, and then have nested blocks. It allows for decent ...
Ian DeRanieri's user avatar
6 votes

Most efficient way to check if a section has any active entries

You can use {{ craft.entries.section('whatever').total() }} for that.
Fred Carlsen's user avatar
  • 2,997
5 votes
Accepted

Is there simpler, less assuming Craft documentation?

Best is to create fresh Craft instalation and experiment, learn basics. I did the same thing when I was assigned to a large drupal project. Here is a resource list on Craft: http://craftcookbook.net ...
Krzysztof Boduch's user avatar
5 votes
Accepted

A Structure section with an entry to a channel index

I like what Matt P wrote in his answer: try to consider how someone [else] will find the logic of the CMS design The other factor you want to consider in information architecture is you only want ...
RitterKnight's user avatar
  • 6,582
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.2k
5 votes
Accepted

Use global values in the Entry URL Format field

Your CraftCMS global can be accessed using the code {{craft.globals.getSetByHandle('siteDefaults').artworksList.first.uri|default}}/{slug} I believe the issue is that the Entry URL field requires ...
Regan Lawton's user avatar
4 votes

How to return a specific entry?

I realize this question was geared towards getting the entry via twig. Here is how you could accomplish the same from a plugin. In my case, I wanted to find an entry via slug. MyPluginController.php ...
Damon's user avatar
  • 4,706
4 votes

A Structure section with an entry to a channel index

Yes that makes sense. There are many ways to approach this. I always try to consider how someone other than me will find the logic of the CMS design i.e. How easy will they find Craft to actually use ...
Matt P's user avatar
  • 1,538
4 votes
Accepted

Parent/child Single sections

Take a look into Entry Types, I'm pretty sure that's a much better way to handle what you're trying to achieve: https://craftcms.com/features/entry-types So you'd have a Structure section (let's ...
Lindsey D's user avatar
  • 24k
4 votes

Parent/child Single sections

Ignoring the obvious "use a Structure" answer, I suppose you could fake a "hierarchy" by placing a child and parent entry field on each of your Single sections and manually assigning entries as ...
Brad Bell's user avatar
  • 67.5k
4 votes

How should an index page be setup/defined in Craft?

Depending on the rest of your site structure, yes you can set these up as Singles. Your other option is to use an Entry Type inside a 'pages' Structure, and in that template you list the first 6 ...
darylknight's user avatar
  • 3,290
4 votes
Accepted

Most efficient way to check if a section has any active entries

Not a definitive answer at all, but you could at least add a .ids() on that so it only retrieves the entry ids and not all the entry data... {% if craft.entries.section('whatever').ids() | length >...
Jeremy Daalder's user avatar
4 votes
Accepted

Nested IA Structure - What's the best way to get it set up?

Lots of question so I'll describe how I would do it more or less. Ask if you want more info. / - single page type. /about - single page type. /industries - single page type. /about/{slug} - ...
Krzysztof Boduch's user avatar
3 votes
Accepted

What's the best way to build URLs for dynamic content collections?

You need that custom route. With the dynamic URI setting the "entry route" is generated dynamically on entry save, but it stores a single, fixed route only. But you don't have to miss out on Live ...
carlcs's user avatar
  • 36.2k
3 votes
Accepted

Using multiple sections VS a single section with entry types

It's hard to answer without examples of your content types. I would suggest that if you would ever need deliberately relate one Entry to another using the Entries field type, then making use of ...
Matt P's user avatar
  • 1,538
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

How can you check if a field exists in a section, not by entry?

The solution is to getEntryTypes() from your section and then access the getFieldLayout() to get to the getFields() (thanks again @Khalwat!). Example: {% for section in sections %} {% if section....
chris's user avatar
  • 906
3 votes
Accepted

Linking to channel page

Create a single section that displays the channel entries so that I can link to it? Are you trying to select the actual Channel itself? (like the News / Blog). Trevor Davis' handy Listing Section ...
RitterKnight's user avatar
  • 6,582
3 votes

Get the URL of a section?

Expanding a little bit more on Dustin C solution. It is possible to get the siteURL instead of hard coding it: <a href="{{ siteUrl }}{{ entry.section.name|kebab }}">{{ entry.section }}</a&...
Alex Ljamin's user avatar
3 votes
Accepted

404s on custom sections and entries

You'll need to create a template, and add the path to that template to the Entry Template field in your "Services" section's settings. For instance, if you create a template called /craft/templates/...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

How to get fields from another section?

I'm not sure that .entry is a valid parameter? I think that craft.entries.section('kontakt') contains an array with entries, so maybe you you could do .first on it, so basically I think you wanted to ...
Youniteus's user avatar
  • 250
3 votes
Accepted

List most recent items combined from Channel and Structure sections

I was presuming that the default Order for Channels and Structure was postDate desc. But it turns out the default for Structure is sortOrder {% set homepageEntries = craft.entries({ section: ['...
John Henry Donovan's user avatar
3 votes
Accepted

Get the section name based on a url segment

Do you mean {% set section = craft.sections.getSectionByHandle(craft.request.getSegment(1)) %} {{ section.name }}
Robin Schambach's user avatar
3 votes
Accepted

Get Entries from a specific Entry Type

$entries = Entry::find()->section('sectionHandle')->type(['yourTypeHandle'])->all();
Robin Schambach's user avatar
3 votes
Accepted

Craft templates in sub directory

It sounds like you're wanting to move templates around like this: articles/index.html articles/_entry.html To this: _layouts/articles/index.html _layouts/articles/entry.html There are three basic ...
Alex Roper's user avatar
  • 2,632
3 votes
Accepted

How can I list Entry Types of a single Section?

You're close – this should work: {% set blogSection = craft.app.sections.getSectionByHandle('blog') %} {% set blogSectionEntryTypes = blogSection.getEntryTypes() %} {% for entryType in ...
Mats Mikkel Rummelhoff'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
Accepted

How do i remove versions from a section after changing section settings to not store versions?

You can prune revisions using the utils/prune-revisions CLI command. This one takes a --max-revisions argument you can set to 0 to prune all revisions. php craft utils/prune-revisions --max-revisions=...
MoritzLost's user avatar
  • 11.3k
3 votes
Accepted

Check which field at which sections is used

I mainly use Inventory plugin for that purpose - it's great, and really useful on larger sites, especially when refactoring/redesigning. Also here's a handy DB query I often come back to which finds ...
James Smith's user avatar
  • 5,189

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