11 votes
Accepted

Display entries if Field Date is past Now

You can combine a for and if statement in twig, so you don't necessarily need to use search. Something like this might get you a bit closer: {% for entry in craft.entries.section('event') if entry....
Steve Holland's user avatar
10 votes
Accepted

How to load entries via ajax when a filter is clicked?

There's a ton of ways to pull this off, but in my opinion setting up pages/URLs for each category is probably a good idea, for SEO and sharing reasons. It's not something that requires a lot of work ...
Mats Mikkel Rummelhoff's user avatar
10 votes
Accepted

Alphabetical index for a list of entries

First, sort all entries by multiple criteria: {# get our entries and order by firstname, lastname #} {% set allEntries = craft.entries.section('entries').orderBy('lastname asc, firstname asc').all() %...
Urs's user avatar
  • 639
10 votes
Accepted

How to order or filter entries by their author's custom field?

This requires a bit of extra work on the ElementQuery, but it can be efficiently done in the same query. We first perform an inner join on the author's content table using the authorId so that the ...
Ben Croker's user avatar
  • 7,411
7 votes
Accepted

Filtering multiple categories with URL queries

The issue with your current code is that you're looping over each type/size category, creating a parameter in your relatedTo query for each one. This means that you're currently creating a query that ...
Mats Mikkel Rummelhoff's user avatar
6 votes

Display entries by category (multiple categories)

You can use .relatedTo(category) {% for category in craft.categories.group('categoryName') %} <h2>{{category.title}}</h2> {% for entry in craft.entries.section('news').relatedTo(...
Marco Schuler's user avatar
6 votes

How to apply multiple Twig filters to text - SOLVED

I believe filters are applied in the order they're written. So in your example you're probably applying the new line breaks with nl2br and then removing them again with hacksaw. Try: <p>{{ ...
Jamie Pittock's user avatar
6 votes
Accepted

How to pull the first block of its kind from a Matrix?

You could try something like this: {% set block = post.buildStory.type('textEditorBlock').first() %} {{block.textEditor}}
alexr's user avatar
  • 608
5 votes
Accepted

Count all unique values

Something like this should do the trick: {% set usersGroupedByCountry = craft.users.limit(null)|group('postaddress.country') %} <ul> {% for country, users in usersGroupedByCountry %} ...
Mats Mikkel Rummelhoff's user avatar
5 votes
Accepted

How to filter entries based on Tags

You can combine multiple relationship criteria by passing an array to the relatedTo parameter with the keyword 'and' or 'or' as the first array element. You want your entries to be related to any of ...
carlcs's user avatar
  • 36.2k
4 votes
Accepted

Filter Sprout Forms entries based on field value, using parameters

Filtering entries is now possible as of Sprout Forms v2.2.0: {% for formEntry in craft.sproutForms.entries.formHandle('contact').firstName('Zoe') %} ... {% endfor %#}
Ben Parizek's user avatar
  • 13.4k
4 votes
Accepted

Reusing logic to set string variables

I would use macros. A Twig macro is basically a function, that can take arguments and render HTML. Macros can be defined inline (i.e. in the same template where it's used) or in a separate file (...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Group by day does strange exeptions

When you specifically group on dateField.day (in your case, the |group('datum.day') part), the group filter won't care about the month or year for the date field โ€“ only the day. This means that any ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Using user-selectable timezones to show localized post dates

It is possible to work around the Craft 2 bug, by converting the Craft DateTime object to a native one. {% set craftDateTime = entry.postDate %} {% set nativeDateTime = date(craftDateTime|date('c')) %...
carlcs's user avatar
  • 36.2k
4 votes
Accepted

How can I let the user activate a particular SuperSort filter

So in order to do this you have to reformat your code and your strategy a bit. You cant provide a Craft query as a link, all that does is grab an array from the database and it won't inherently print ...
Alan Miller's user avatar
3 votes
Accepted

Filter syntax for Dimensions & Weight?

There is currently no filter but you can access the units of measurement from your settings, and display the measurement: {% set weightUnits = craft.commerce.settings.weightUnits %} {% set ...
Luke Holder's user avatar
  • 6,827
3 votes

Display entries if Field Date is past Now

Craft has changed since the above answer was given. The now object must be a part of the string, rather than concatenated as an object. so instead of: {% set futureEntries = craft.entries.section('...
ToddPadwick's user avatar
3 votes

Add '...' to template field

You might find the Hacksaw plugin useful for this https://github.com/ehousestudio/craft_hacksaw/ this will truncate text for you and has a wealth of options available for doing so, specifically the ...
Alec Ritson's user avatar
  • 4,539
3 votes
Accepted

Order by fields after searching

Not really feasible without a plugin โ€“ fortunately, there's the excellent SuperSort: {% set results = craft.entries.section('player').search('team:"thenameoftheteam"') %} {% set ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Convert characters to Ascii

I would use a combination of things: Twig's replace filter to convert รค to ae etc. Twig's convert_encoding filter to eliminate any remaining non-ascii characters Craft's kebab filter to do its thing ...
Marion Newlevant's user avatar
3 votes
Accepted

How to output a Rich Text Link to an Entry as a tooltip?

Not really a craft solution โ€” but easiest might be jquery/ajax. Since you know the base URI, you can just create a selector for the route, and work from there. $("a[href*='route/to/definitions/']")....
Douglas McDonald's user avatar
3 votes

How I can sort my entry that belong to 3 section on date?

Try chaining the sections together like: {% set allEntries = craft.entries({ section: ['blog', 'news', 'caseStudies'] }).orderBy('elements.dateCreated asc').all() %} Then {% for entry in ...
Jamie Jenkins's user avatar
3 votes
Accepted

How do Twig filters interact with concatenated strings and shorthand "if-else" ( `var ? true : false` ) strings?

You are asking about Twig's operator precedence: The operator precedence is as follows, with the lowest-precedence operators listed first: ?: (ternary operator), b-and, b-xor, b-or, or, and, ==, !=, &...
Marion Newlevant's user avatar
3 votes
Accepted

Element API: Get Entries Related to Category with Query Parameter

Are you passing the projectCategory parameter as a string or ID? In any case, the relatedTo parameter will receive a string in your code, which might trip up the query. If the parameter is passed as ...
MoritzLost's user avatar
  • 11.3k
2 votes

Filter entries by entry type in the CP?

To enable sorting on Entry Types in the Section's index table, you can add this to a custom plugin's primary class: public function modifyEntrySortableAttributes(&$attributes) { $attributes['...
Mats Mikkel Rummelhoff's user avatar
2 votes
Accepted

How to filter entries in multiple category groups by selecting multiple categories

After a lot of back and forth and reading various posts on this I thought I would submit my answer. There maybe better ways of doing what I ended up doing but hopefully this will provide a start for ...
Gareth's user avatar
  • 1,605
2 votes

Twig filter to convert special characters to URL friendly characters

My first idea would be to use the url_encode filter than would turn your special characters into a URL friendly format. I imagine these would also be Javascript friendly. If you'd like to convert the ...
Luke Pearce's user avatar
  • 3,863
2 votes

How to load entries via ajax when a filter is clicked?

I used the accepted answer here as a starting-off point, and I came up with this solution. I know this looks a little convoluted, but it's actually quite minimal given the the size of the site I'm ...
InanisAtheos's user avatar
2 votes
Accepted

Add '...' to template field

Try something like {{ (entry.body | slice(0, 500) ~ '...') | markdown }}
Seán O'Grady's user avatar
2 votes

Google AMP Filter

You could use the replace filter, it accepts regex: https://craftcms.com/docs/templating/filters#replace
andrew.welch's user avatar
  • 11.6k

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