Simon Kuran
  • Member for 7 years, 7 months
  • Last seen this week
Get category title by slug
Accepted answer
24 votes

You need to add .first() when setting the category. As far as I can tell, if you don't have .first() only {{ category.slug }} will work. First get the slug: {% set catSlug = craft.request.getSegment(...

View answer
How to create a CMS editable channel section index page?
Accepted answer
13 votes

Create a Single called "Blog Overview" and set its URI to "blog" and its "Entry Template" to "blog/index" (your blog listing template). Then just override the title to "Blog" either by hard coding it ...

View answer
How can I add a dynamic "active" CSS class to the navigation on any given page?
12 votes

Here's yet another way you can do it (in some circumstances) and it's nice and DRY: Craft 2 {% if craft.request.getPath() == entry.uri %} Craft 3 {% if craft.app.request.pathInfo == entry.uri %}

View answer
Can I run one Craft install on multiple domains and/or subdomains?
Accepted answer
12 votes

Update for Craft 3 Craft 3 includes native support for multi-site installation. Here's a link to the official docs and here's a link to another question with more resources. Old answer for Craft 1 &...

View answer
How to retrieve Site Url and Site Name in Plugin
11 votes

In Craft 3 you can do this: use craft\helpers\UrlHelper; UrlHelper::siteUrl(); Craft::$app->sites->currentSite->name;

View answer
Entry Types Custom Slug
Accepted answer
10 votes

You could just set your "Entry URL Format" to: my-section/{type.name}/{slug} Your entry type names couldn't be as clean when composing entries in the CP as you'd need to set them to something like "...

View answer
Is Redactor's default config saved as a .json file anywhere?
Accepted answer
9 votes

As @Brandon said, the defaults are hardcoded in redactor.js so there isn't a default.json file, but if there was, this is what it would be (from Craft 2.3.2615): { buttons: ['html', 'formatting', ...

View answer
Structure - Add class if element has children
Accepted answer
9 votes

The Methods section on the EntryModel documentation page has a lot of useful things for working with navigation for Structure sections. You can use hasDescendants(): {% if entry.hasDescendants() %}...

View answer
Listing categories alphabetically & total post count
9 votes

The relatedTo param will do the trick: {% set entries = craft.entries.limit(null) %} {% for category in craft.categories.relatedTo(entries).order('title asc') %} {% set entryCount = entries....

View answer
Identify immediate siblings block type in matrix
Accepted answer
8 votes

Fun question! :) You can use getNext() and getPrev() Methods on the MatrixBlockModel documentation page. {% for point in entry.keyPoints %} {# if this is the "typeToWrap" block type #} {% ...

View answer
Get structure top ancestor
7 votes

getAncestors() gets all entries that are ancestors. Since you're looping through them what rootEntry is set to last time through is the closest ancestor. You can avoid the loop and just get the first ...

View answer
How can I limit a list based on a custom date field
Accepted answer
7 votes

I think .after would work, but I've used this way: {% set entries = craft.entries.section('events').limit(null) %} {% for entry in entries.eventDate('>=' ~ (now.date)).order('eventDate DESC') %} ...

View answer
Test for empty field?
7 votes

Stuart's answer totally works. You can also use Twig's length filter: {% if article.articleImage|length %}

View answer
Is there any way of specifying a default category for a category field?
Accepted answer
6 votes

You could output the categories in a way that makes them look like they are from a specific category when they don't have any categories assigned to them. When you're outputting any of the entries, ...

View answer
My license.key file missing. How do I transfer the license to other servers?
6 votes

The Craft .zip does not come with the license.key file. From the Craft docs: "It doesn’t get one until you have finished installing Craft and it has made its first call to our web service to check for ...

View answer
Looking to use a tag slug/URI and loop through entries of that tag
Accepted answer
6 votes

Here's a really DRY way to do it. Setup a route, something like "news/tags/(tag)" to load the "news/index" template (the same one used for listing all entries). In the "news/index" template: {# If ...

View answer
How can I create a simple loop through entries in a category?
6 votes

Here's another good example for working with categories that may be useful to you. This will loop through all categories (that have entries) and show their entries: {% set entries = craft.entries....

View answer
How do I display an entry's tag?
Accepted answer
6 votes

To list all tags on a particular entry use: {% for tag in entry.tagField %} {{ tag }} {% endfor %} If you only want the first tag you can just use: {{ entry.tagField.first }}

View answer
Creating a date filtered archive template
5 votes

I've used this method for sorting by year and month (it could be expanded to support days). On the news/index.html template: {% if month is defined %} {# show an archive of a month #} {% set ...

View answer
Output values from all entries in a specific section EXCEPT those with a specific category id
3 votes

You can get the entry IDs that have are related to the category and then exclude them from the all the entries. {% set entryIdsWithCategory = craft.entries.section('driverPositions').relatedTo('7192'...

View answer
Load a specific file/CSS only in a certain page
3 votes

You can check a specific URL segment. For example if you need to load some CSS on the About page and that URL is yoursite.com/about you can do this: {% if craft.app.request.segments|first == 'about' %...

View answer
Can you relate entries from more than 1 section?
Accepted answer
3 votes

Yes, you can. When creating an entires field the Sources option is where you select which sections you'd like to be able to select entries from. See Entries Fields in the docs.

View answer
Should I use tags for cities?
3 votes

I agree with Victor, but if you're looking to loop through all the cities (regardless of how many you have) and show entries related to them I'd do it like this: {% set entries = craft.entries....

View answer
Pagination Slug Issue
Accepted answer
2 votes

Pagination is for breaking up a list of entries into different pages. p3 means page 3 of entries. What you're looking for is the ability to link to the next/previous entry. If you are ordering your ...

View answer
How can I only allow authors to edit their own entires via front-end?
Accepted answer
2 votes

You can check if the current entry's author is the currentUser. {% if entry.author.id == currentUser.id %} {# User can edit entry #} {% endif %}

View answer
Getting ancestors for manually set parent in template
2 votes

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

View answer
Matrix Field Slug Output
Accepted answer
2 votes

That is returning an ElementQuery. I'm assuming you only need to get the first category. You need to use .one to get the category element. {% for row in entry.matrixField.all() %} {{ row....

View answer
Entries field templating only when entry is added
1 votes

You'll need to do something like this. entry is a How to videos entry. {% set relatedProducts = entry.productsEntryField.all() %} {% if relatedProducts|length %} {% for product in relatedProducts ...

View answer
Show Category Title only where an entry has been included in an Entries field
Accepted answer
1 votes

You just need to check if it's related to the current entry. entry is the entry you're displaying. {% for category in craft.categories().group('someGroup').relatedTo(entry).all() %} {{ category....

View answer
Embedding a podcast player onto my Craft site
1 votes

Not having access to the templates could make this hard to troubleshoot. Are you pasting into the HTML editor of a Redactor field? If so try editing the field's advanced options. Uncheck Remove inline ...

View answer