Skip to main content
12 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

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

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

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

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

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,548
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

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,642
3 votes
Accepted

How can I list Entry Types of a single Section?

You're close – this should work in Craft 3.x and 4.x (look at @obs answer for Craft 5): {% set blogSection = craft.app.sections.getSectionByHandle('blog') %} {% set blogSectionEntryTypes = blogSection....
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.5k
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,344
2 votes

Get the URL of a section?

I know this is a year old, but I was scratching around trying to find a solution to this, and I came up with this. Try the kebab modifier. <a href="http://example.com/{{ entry.section|kebab }}"&...
Dustin C's user avatar
  • 379
2 votes

Is there any way to set a default status for Entries, either globally or per Section?

As of Craft 2.6.2771, sections now have a “Default Entry Status” section.
Brandon Kelly's user avatar
2 votes
Accepted

Current Section handle

You can get the current section handle from the entry like so {{ entry.section.handle }}
Fyrebase's user avatar
  • 735
2 votes
Accepted

Is it possible to limit the number of times a user can be added to the same field across different entries?

Could you not come at it from a different angle and instead choose your team by editing the user? That way you can assign a team field to the user and restrict that field so that you can only pick the ...
Steve Holland's user avatar
2 votes

How to make a code/settings for accessing the one database from 2 different html files with {slug}

This makes more sense :) So basically, you want to have info from one entry on multiple pages and your problem is that in the section settings, you can only define 1 template for an entry. One way ...
Tom De Smet's user avatar
  • 1,456
2 votes
Accepted

Count table field values in certain section

You can get the total amount of rows like this: {% set totalcount = 0 %} {% for entry in entries %} {% set totalcount = totalcount + entry.artikelnummer|length %} {% endfor %} Edit In the ...
Jan_dh's user avatar
  • 858
2 votes
Accepted

Many sections use one template: How do I get current section?

If I understand you right, you could just use the Entry Model which is automatically populated as entry if you call the Index. Entry Model objects have a method getSection() which returns the Section ...
Johannes's user avatar
  • 740

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