Skip to main content
9 votes
Accepted

Creating partials outside of the templates folder

So a few potential things to consider: You do not want to be serving static assets like Javascript, CSS, etc. out of the templates directory. I realize you're planning to put them "elsewhere", but ...
andrew.welch's user avatar
  • 11.6k
8 votes
Accepted

Does Craft CMS support these features?

Preview function for different devices, screen sizes and screen configurations(portrait/landscape) Yes it has live preview. However this isn't per device. You can open the entry with a secret url ...
CreateSean's user avatar
  • 1,983
8 votes
Accepted

Which is best practice, SET or FOR?

Regardless of the number of elements involved, Craft will return an iterable ElementCriteriaModel whenever you query for content (e.g. via craft.entries, or using relational FieldTypes like Assets, ...
Mats Mikkel Rummelhoff's user avatar
6 votes

Creating partials outside of the templates folder

I've been making use of macros to create a component based architecture in a recent project. I've found this way of working useful in a few different ways: Jumping around your codebase is much easier ...
Luke Pearce's user avatar
  • 3,863
6 votes
Accepted

Craft CMS images transform srcset sizes

You can use the method Asset::getSrcset to generate a valid srcset attribute as well as the asset transforms included in it. But you will need to restructure your HTML a bit. The current approach ...
MoritzLost's user avatar
  • 11.5k
5 votes

Which is best practice, SET or FOR?

Both are essentially the same query, the only thing that differs is the WHERE statement. The ID approach will always be the most efficient, since it uses the primary key index, thus finding the result ...
Gustavs's user avatar
  • 406
5 votes
Accepted

A more economical method of building an archive menu?

If you know which years should appear, and there are no breaks in the timeline, perhaps it would make more sense to do a simple numeric loop instead... {% for year in (now.year)..2009 %} {{ year }...
Lindsey D's user avatar
  • 24k
4 votes

Understanding Eager Loading

Your syntax is a bit off. The withTransforms parameter is an Asset criteria, meaning it is only relevant when you're pulling Assets. Appending it to entry.relatedArticles (an Entries field, returning ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Query all categories once and get individual categories from array

Your issue is that as soon as you call .find(), your ElementCriteriaModel returns an array of elements. In other words, the ElementCriteriaModel is gone, and it's no longer possible to add parameters (...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Why is Craft extremely slow when using a shared, external database?

My suggestion would be to do what is outlined in Database & Asset Syncing Between Environments in Craft CMS It's a little bit of logistical organization coupled with some scripts to do the asset/...
andrew.welch's user avatar
  • 11.6k
4 votes
Accepted

Craft incredibly slow site performance

It turned out this was the culprit. Craft was doing a deprecationerrors query (https://github.com/craftcms/cms/issues/2539). Turning devMode to false fixed this. Hope this helps someone...
Hassan Mahmood's user avatar
4 votes
Accepted

How to speed up a single entry page with Eager Loading

Disclaimer: While eager-loading will almost always bring down the total number of queries executed, it's important to note that having less queries won't always equal better performance. When ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Is it possible to display the debug bar while NOT logged in?

I don't think there is an option in craft to do that, but if you really wanted to do this you can create your module and add this code inside the init function. $request = Craft::$app->getRequest()...
aodihis's user avatar
  • 801
3 votes
Accepted

Caching and TTFB with Craft

This isn't an issue with Craft, from the POV that the TTFB should be pretty consistent. How are you testing it? My guess would be that the issue is with your hosting. These two articles may help you:...
andrew.welch's user avatar
  • 11.6k
3 votes

Understanding Eager Loading

Thanks for this Mats. Is there a general guide as to when you should really use Eager loading? I am not seeing much improvement The article Speed up your Craft CMS Templates with Eager Loading I ...
andrew.welch's user avatar
  • 11.6k
3 votes

Creating partials outside of the templates folder

Some good answers already by Luke and khalwat. I wouldn't try to load any templates outside of the normal Craft folder... you get into plugin territory there and it's not necessary. Your templates ...
RitterKnight's user avatar
  • 6,582
3 votes

Sluggish Asset Indexing

One way to get around this is to create a new Asset Source (let’s call it “Staging”). Add the folder of unindexed images/assets into Staging, our new asset source (which should otherwise be empty). ...
rungta's user avatar
  • 105
3 votes

Expected performance benefit of using a non-file CacheMethod (Redis, Memcache)

How many servers do you have? Redis and Memcached are most beneficial/intended for a multiple server setup so if you only have one server, there's probably other/betters thing to worry about. (Best ...
RitterKnight's user avatar
  • 6,582
3 votes
Accepted

Expected performance benefit of using a non-file CacheMethod (Redis, Memcache)

As with most performance related questions, the answer is "it depends". :) Apps like Redis and Memcache store their key => value stores in memory as opposed to disk-based file caching. Accessing ...
Brad Bell's user avatar
  • 67.5k
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
Accepted

Deleted matrix block means deleted data?

Any content or relationships that belong to the Matrix block will also be deleted, when you save the entry. If there were any relationships, the target elements won’t be deleted, though.
Brandon Kelly's user avatar
3 votes
Accepted

Correctly using eager loading in Plugin development

Eager loading only works when your field is a RelationField it does not work with Text fields. If you goal is to reduce the length of the queries and to maximize your performance you could fetch the ...
Robin Schambach's user avatar
3 votes
Accepted

Sprout reports timing out on thousands of records

As you suspected, Sprout Reports is not designed to handle large quantities of data if it's more than your server can handle. As for how many records you could export, it really just depends on how ...
Ben Parizek's user avatar
  • 13.5k
3 votes
Accepted

Is it worth caching product blocks for use on a category page?

In short, it's worth caching anything that is at all time expensive, really. It's always going to be significantly quicker to retrieve a cached chunk from the DB by key versus parsing a template ...
Jeremy Daalder's user avatar
3 votes
Accepted

Improve performance and element queries when used multiple times

Since you have two sections, you will need your two initial queries, however, in your example, although you are eager loading the children (with(children)), you are querying them a second time when ...
Oli's user avatar
  • 7,495
3 votes
Accepted

Will having the Craft storage directory (CRAFT_STORAGE_PATH) on a Digital Ocean Volume (like AWS EBS) dramatically affect CMS save performance?

Even if a request (or specifically an Element save operation) doesn't make much use of a file-based cache, it will likely compile and read templates from the storage directory. Logs will also be ...
August Miller's user avatar
3 votes

Eager loading categories and assets inside related entries for gallery

A good thing to know about Craft is that all relational fields (such as your Assets field galleryEntry.assetGallery, for instance) return element query objects. So, all methods and parameters ...
Mats Mikkel Rummelhoff's user avatar
2 votes

Expected performance benefit of using a non-file CacheMethod (Redis, Memcache)

Here you can find an interesting benchmarking between Redis (remote or local) and Python Disk caching. The answer from Didier Spezia is good enough to understand the results. https://stackoverflow.com/...
coterobarros's user avatar
2 votes

Slow initial response time when website has been idle?

You mention you're using cache, which could mean a whole lot of things, but the symptoms you're describing are typical of what you'd see if you're doing some heavy-handed things inside of a {% cache %}...
Brad Bell's user avatar
  • 67.5k
2 votes
Accepted

Better way to group by category and include full category entry

Your actual code is pretty effective – the problem is that it's potentially going to result in a lot of queries. This is a good example of the so-called N+1 query problem, where each iteration over ...
Mats Mikkel Rummelhoff's user avatar

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