New answers tagged

0

I'm writing a "build a favorite board games library" in Craft CMS 3 tutorial. Outline: Setting up local development, cover Craft's building blocks, import data, create front-end templates, style it with Tailwind CSS & deploy to a server. The first 3 lessons are up: Craft CMS 3 Local Development with Lando Docker Create a Board Games section in ...


1

I'm working on solving a similar problem and I've come up with a solution that stores a string of comma-delimited IDs in the session like this: {% set displayedContentIds = craft.app.session.get('displayedContentIds')|split(',') %} This code is added to all components on the page that are required to exclude content that's already been shown further up the ...


2

Searching against lightswitch should work. Make sure Use this field’s values as search keywords is checked in Settings → Fields → your field then run ./craft resave/entries --update-search-index to (re)index your values.


2

The Sprig plugin makes this rather straightforward to achieve. Any time the category is changed, the component will re-render itself and display the resulting entries. {{ sprig('_components/filteredEntries') }} {{ sprig.script }} {#--- _components/filteredEntries ---#} {% set categoryId = categoryId ?? '' %} <select sprig name="categoryId"&...


1

Just to add to the answer above, in plain text the answer would be: 'and, not 1, not 2' Or, in an entry query: {%- set entries = craft.entries({ section: 'blog', id: 'and, not 123, not 456, not 789', }).all() %}


3

Yep! It's not super well documented, but there's a little information about it down in the Advanced Element Queries section of the docs. It would look something like: {% set titleList = craft.entries.section('articles').select('title').column() %} One thing to note, if you're selecting a field value instead of the title, the select parameter will look ...


2

This could also be accomplished with the map filter, if you’re running Craft 3.1.29 or later: {% set users = [ {name: 'Bill', age: 25}, {name: 'Tim', age: 30}, {name: 'John', age: 32} ] %} {% set users = users|map(u => u.name == 'Tim' ? u|merge({age: 31}) : u) %}


1

It transpires that the problem actually relates to some seemingly undocumented behaviour of the {% exit %} call. When the ENVIRONMENT .env config is set to dev this appears to flush the buffer and terminate processing, but in staging or production mode, it appears to simply stop processing. (Even manually calling {% flush %} before {% exit %} doesn't appear ...


2

It looks like you're reinventing the wheel here: in Settings → General, you can toggle the site live/offline. When the site is offline, Craft serve the templates/503.twig templates, no matter which URL you hit. You can even configure users to have access to the site, when it's offline. To do so, go to the user edit page in the control panel and then to the ...


1

I finally found the solution! i was not aware, that the document-root HAS to point to the /web folder. There were old web applications on the server, which prevented to change the root. So i made the .htaccess file, to redirect to the /web folder. But apparently, this is not going to work. So keep in mind, to point to the right folder.


3

Check out "Dynamic Content" in the "Advanced Usage" section of the Blitz docs: https://putyourlightson.com/plugins/blitz#dynamic-content Thus can be done with: {{ craft.blitz.getTemplate('/template/name', { elementId: entry.id }) }}


2

You can't and it's a good thing. Your external JS file is meant to be static so it can be cached by the visitors' browser. One way to achieve what you want is to only define the addToMap() function in your external JS file and call this function from your template, passing it the locations to display. Here's how you can do this from your template: {% if ...


Top 50 recent answers are included