New answers tagged

2

You need two different fields since you can only select one category group per category field. As you said, having two fields with the same name isn't possible. One way to work around this would be to add a behaviour that checks the entry type and returns the categories from the corresponding field (i.e. jobCategories for job entries and blogCategories for ...


1

After some further trial and error I have made this work like so. However, it feels like there is or should be a simpler method....what am I missing or what is a better approach? {% set selectedVehicle = craft.entries .section('vehicles') .id(vehicle) .with( [ 'vehicleBrand', 'oemFixings', 'afterMarketFixings' ]) .one() %} {% set ...


3

You could use filter to get only the variant that matches the wheelSpacer variable. This will return an array, so you can use first to get the first matching variant (since presumably product.variants won't contain duplicate variants). This has the added benefit of getting you the matching variant directly, instead of it's ID: {% set variant = product....


2

Using the |map filter would work nicely here: {% set variantIds = product.variants|map(variant => variant.id) %} {% if wheelSpacer in variantIds %} ... {% endif %}


1

Caveat: This is totally untested, and could be nonsense. I'm sure you'll let me know. It assumes that the Craft element query methods can be used here. If you have a 'lang' value, add a where to your basic assets element query {% set folderId = craft.app.request.getQueryParam('folderId') %} {% set query = craft.app.request.getQueryParam('q') %} {%...


2

Found it, this works: <img src="{{ dataUrl('@webroot' ~ myAsset.getUrl({width: 200, height: 200}, true)) }}" /> Two important things: prepend the @webroot alias to the myAsset.getUrl(...) set the second parameter of getUrl(...) to true: myAsset.getUrl({...}, true). This ensures that a real file path is returned by getUrl, because the image ...


1

You can use Asset::setTransform or Asset::copyWithTransform to get (a copy) of the asset object with your transform applied. Then you can pass that into dataUrl(). {# Apply the transform to myAsset directly #} {% do myAsset.setTransform({width: 200, height: 200}) %} {{ dataUrl(myAsset) }} {# Use this if you need myAsset without the transform later #} {% ...


1

One method that comes to my mind is to create an asset configuration in admin panel (Settings -> Assets), where you can create different Image Transform configurations. For example, I can create an Image Transforms called Thumbnail then set the required dimensions and quality of the image. Once you create an Image Transforms, you can utilize them with ...


1

You don't need to use Javascript/jQuery for this. You can get the the current url from craft.app.request in some way and do a check as you output your navigation. It looks like you have some custom fields for urls but, For instance, if you wanted to check the last url segment you could use craft.app.request.segment(-1) to get it. Then when outputting your ...


2

You should take a look into Craft's index.php file. It sets some constants, autoloads Composer dependencies and loads the environment file before actually loading the script that you tried. Here is the snippet: <?php /** * Craft web bootstrap file */ // Set path constants define('CRAFT_BASE_PATH', dirname(__DIR__)); define('CRAFT_VENDOR_PATH', ...


2

You're close! Because an asset field can potentially contain multiple items you need to explicitly select the first one, so: {% set video = component.video.one() %} But that doesn't get the actual url of the video, to get that you need to request it: {{ video.url() }} So in your case: {% set video = component.video.one() %} {% if video %} <video width=&...


9

You can do this using PhpStorm’s Language Injections feature. In fact, as of PhpStorm 2017.3, it has included support for {% script %} tags out of the box. To extend that to {% js %} tags, go to Preferences → Editor → Language Injections, and search for “twig: custom statement javascript”. Double-click on it to edit it, and add the following line to the ...


2

I would use a macro to output the contents of a single nugget (matrix block), this way you don't have to repeat the include statement multiple times. The only thing you need to keep track of is the current index, i.e. which item is next. You can't do this inside the macro, since a macro can't have persistent state. You have two options: Set up a variable to ...


Top 50 recent answers are included