Hot answers tagged

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

Assuming the Assets field on your block has a handle of asset, you could do: {object.asset.one().kind}/{owner.slug}


1

You can access the field in the entry by using the normal array syntax, $entry[$fieldHandle]. Depending on whether or not the field is eager-loaded, this will now be either an ElementQuery, which you can run ->all() on, or an array of assets. When you have the asset, you can use $asset->getUrl($transform) to get the URL to a transformed image. use ...


1

I'm not sure why you need it checked in your exact scenario but this was added in 3.4.21. Information on it here: https://github.com/craftcms/cms/blob/develop/CHANGELOG.md#3421---2020-05-28 and here: https://github.com/craftcms/cms/issues/6113)


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


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