August Miller
  • Member for 6 years, 3 months
  • Last seen this week
Get array of titles instead of whole collection of entries' attributes
Accepted answer
6 votes

Unfortunately, the answer differs pretty dramatically for native properties with "stable" column names and for Content, which (as of Craft 3.7.0) now contain a "suffix" that (in ...

View answer
Site loads funny
Accepted answer
6 votes

This looks like a problem with your DocumentRoot config option. If you have access to your Apache VirtualHost configuration, you should append /public to your DocumentRoot. If you're configuring the ...

View answer
I can't add a body field?
Accepted answer
6 votes

You've probably gone through the process of creating a new Section, but have not assigned any fields to it. In Craft, the differences between each of your Sections and Entry Types comes in the ...

View answer
How do you reset a cart under Craft Commerce 2?
Accepted answer
5 votes

The commerce/cart/remove-all-line-items action (or in Craft 2 terms, commerce/cart/removeAllLineItems) was deprecated (and subsequently removed in Commerce 3), so it's up to you to build a form to ...

View answer
Is there a way to compare what has changed on an entry while it's being saved?
Accepted answer
5 votes

You're probably looking for Element::getDirtyAttributes() and Element::getDirtyFields()! The former is for native class properties/attributes (and is based on an ActiveRecord pattern in Yii, I believe....

View answer
How do I "register" a service in a Craft 3 plugin?
5 votes

It turns out there's a handy method for manually registering your services, or in Yii2 parlance, just "components": namespace example\myplugin; use example\myplugin\services\Example as ...

View answer
Where is the documentation for creating templates/themes?
5 votes

Each Craft install is typically considered a discrete site, with its own design, information architecture, assets, etc. This is why you might not be seeing information about "theming," per se. ...

View answer
lowercase breadcrumbs
Accepted answer
5 votes

You can do this with CSS, or with Twig. CSS: ul.crumbs li { text-transform: lowercase; } …or, if you need to start after a particular index… ul.crumbs li:nth-child(n + 2) { /* Start with the 2nd ...

View answer
How to immediately redirect to an entry after creating the new entry from a frontend form?
Accepted answer
4 votes

I think the answer is as simple as providing the new Entry's URI to the redirectInput function: <form method="POST"> {{ actionInput('entries/save-entry') }} {{ redirectInput('{uri}'...

View answer
CSRF in “Headless” Applications
Accepted answer
4 votes

A similar question was asked in the Craft Slack today, so I thought I'd transcribe the consensus: Internally, CSRF tokens come from a call to Craft::$app->getRequest()->getCsrfToken(). This ...

View answer
Entry Post Date Format time since - X days ago
4 votes

It looks as though Craft 3’s built-in duration Twig filter might help: Posted {{ entry.myDateField.diff(now) | duration }} ago. With a bit of additional logic, you can make this more useful, after ...

View answer
Craft CMS plugin with AJAX gives 404 error
4 votes

If you aren't currently logged in, you're apt to be running up against the "anonymous access" limitation. This section of the Controller documentation should help: By default, controller actions ...

View answer
Edit Entry Page
Accepted answer
3 votes

Andrea's answer is part of the solution! You'll need to set up a route, either via routes.php, or via the admin. I tend to prefer PHP routes, so you never have to worry about the functionality being ...

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

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

View answer
Why do i get an Invalid route error in cp when calling plugin action?
Accepted answer
3 votes

I think my other answer is also part of this one. The only specifics I'd add here is that your action is getting "double-declared," in a way. Using the action param in a request has a lot of ...

View answer
Displaying notification in control panel
Accepted answer
3 votes

Craft's JS/UI framework "Garnish" is largely undocumented, but exploring the Craft object it exposes in the console, I found a few methods that might be useful: // Good for confirmations (...

View answer
Can I apply adjustments (discounts) through a controller?
Accepted answer
3 votes

Generally speaking, no. Adjusters should always be computed from the current state of the order—the information required to match an Adjuster should be attached directly to an order. Your custom ...

View answer
Where does Craft store HTML Templates?
3 votes

It sounds like you have access to the CP, but not the server. In order to modify the template files (usually stored in the templates directory, next to the public web folder), you'll need SSH or FTP ...

View answer
How to query an entry by a custom field in Craft 3
3 votes

I might be missing some important SQL-ism, here, but I think the question has a much simpler answer. The ElementQuery docs bury it a bit, and I wonder if many new Craft developers have trouble ...

View answer
Choose not to save an element on EVENT_BEFORE_SAVE_ELEMENT
Accepted answer
3 votes

This functionality or behavior is a bit confusing. The Elements Service has its own Events for saving Elements, specifically... but because ultimately Elements are just Yii Models, they have a ...

View answer
Check for number less than x in array
Accepted answer
3 votes

Twig isn't very well equipped to deal with more than basic logic and comparisons, but you can accomplish some of these tests with a bit of extra juggling: {% set constraintMet = false %} {% for ...

View answer
A hash key must be followed by a colon (:) syntax error
3 votes

You're nearly there! The and query you’re building just needs to be declared as an array: {% set puppyAnimals = craft.entries({ section: 'animals', orderBy: 'postDate', animalDateOfBirth: ...

View answer
Routing: How can I ignore a parameter in route definition?
Accepted answer
3 votes

It sounds like you might be trying to blend Craft/Yii routing with Rewrites (if you're coming from an Apache background). I believe what Craft interprets this as is an attempt to map a request to ...

View answer
Overwriting specific method in plugin
Accepted answer
3 votes

If the methods you need to alter are part of an auto-instantiated Service in the PerForm plugin, you might consider using Yii 2 “Behaviors.” From the docs: …to attach a behavior dynamically, call ...

View answer
Getting Commerce Products using Element API in Craft 3
Accepted answer
3 votes

You're so close! Just one change (see the elementType key, and the added comment)… use craft\commerce\elements\Product; return [ 'endpoints' => [ 'api/search' => [ '...

View answer
Demo repo for an Adjuster module for Commerce 2?
Accepted answer
3 votes

I've created a stub/reference Adjuster module, here. This demonstrates how to register two Adjusters via a custom module—one that creates a 5% discount on each line item, and one that creates a 10% ...

View answer
commerce/cart/updateCart throws page not found
Accepted answer
3 votes

Based on your tag, I assume you're using Commerce 2. Controller actions in Craft 3 use kebab-case, now, so your action should be commerce/cart/update-cart.

View answer
Is it possible to change the amount of time a user stays logged in for?
Accepted answer
3 votes

Yes! The setting is called userSessionDuration, and you can set it in your general.php config file, on a per-environment basis. Here's an explanation of the values that you can use for the setting—...

View answer
Plugin logging not appearing
2 votes

At first, I didn't internalize the substance of the log message, and assumed the logger was filtering out your statement due to the target's configured "levels." However, considering that ...

View answer
Compare entry checkboxes with user groups to give access
Accepted answer
2 votes

There isn't an officially-supported way of gating read-access like this, so it's up to the template or view layer (or potentially a custom Module) to implement the logic. I believe the behavior you're ...

View answer