New answers tagged

3

Just to expand on the caveat regarding field suffixes in Craft 3.7+, I asked on Github what the recommended way to include field suffixes in a custom query is. Here's brandonkelly's response: The easiest way to do it would be to just hardcode the column name in your template. It won’t change between environments or anything. That said, it does feel kind of ...


5

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 most any other case) is not a concern for developers. More on that in a moment. Titles For titles, it's as simple as using the .select() method native to the ...


1

I ran into the same issue today with a fairly old project and was able to fix it by rolling back to Composer 1 locally (composer self-update --1), then updating all of the dependencies and reinstalling, then switching back to Composer 2 (composer self-update --2) and running composer install a second time to pick up on any C2-specific changes.


2

You've eager-loaded the matrix block(s), but not the image(s) within them. Change to something like this to eager load both, assuming you have named the block type "asset" and the asset field "image": {% set teamEntries = craft.entries() .section('team') .with(['teamPortrait.asset:image']) .limit(3) .all() %} (To ...


3

At the moment, you are loading all categories in the line {% set categories = categoryEntry.all() %} and that's why you are getting them all for each entries. What you need to do is to fetch your categories in the context of your blogEntry. Here I assume a field name of blogCategories on your blogEntry but change accordingly to match what your Categories ...


1

Thanks to help from Ryan on the Discord group, I found an anwser. This being… // Call the channel {% for serviceEntry in craft.entries.section('service').limit(3).all() %} <h1>{{ serviceEntry.title }}</h1> <p>{{ serviceEntry.excerpt }}</p> <ul> // Call the block within the loop {% for block in serviceEntry....


1

Craft has a newer asset method called getSrcset which should be close to what you need. Here's the code example from the docs: {% do asset.setTransform({ width: 300, height: 300 }) %} {{ tag('img', { src: asset.url, width: asset.width, height: asset.height, srcset: asset.getSrcset(['1.5x', '2x', '3x']), alt: asset.title, }) }} You can also skip ...


1

Your controller looks ok, though I would clean it up a bit and use more expressive variable names to reduce the surface area for bugs: $templateVariables = [ 'status' => true, 'message' => 'Sucess' ]; return $this->renderTemplate( 'craft-handle/test.twig', $templateVariables ); Now you will have access to the variables status and ...


2

You can write a function, a utility template or a macro to make repetitive tasks like generating responsive images easier. I usually prefer templates, because they're easy to extend and they can take a lot of optional arguments without the user needing to pass all of them. Building your own utility templates is a good time investments, since you can create a ...


1

Simple fix. The error was being caused by wrapping the freeform render in tags. Removing these changed the request type and now it works. Ex: It should be: {{ craft.freeform.form("contactForm").render() }} and not <form> {{ craft.freeform.form("contactForm").render() }} </form>


2

As far as I know there is no plugin that has this feature. If there is none you would have to write a custom module for that. The module would have 4 main responsibilities. get all users that are subject to get notified compose a notification for each of them send them (in a sync manner or as queue jobs, if you expect to have a lot of inactive users) expose ...


3

Not sure if there is a plugin that does this automatically, but you can build a small module that accomplishes this. Since it should run automatically in the background, I would create the functionality as a custom console command and then execute that command regularly in a cron job (for example, daily or hourly). The command would do the following: Check ...


2

I'm going to lay out the answer here, in case someone else runs into someone else's issue. We are using Postmark to process emails. All of the failures in the queue are email addresses that have previously hard bounced in postmark. The reason it's always the shipping confirmation email has nothing to do with the shipping confirmation email, but the fact that ...


2

You can use craft.assets() to search for assets, the same way you can use craft.entries() to find entries. See Querying Assets for details. Asset queries allow you to use mostly the same methods that entry queries do. For example, you can also use the .search method to search for keywords in the asset's title and searchable fields. {% set searchQuery = craft....


Top 50 recent answers are included