Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [lightswitch]

The tag has no usage guidance.

1
vote
1answer
19 views

filter matrix blocks by multiple light switch value, and then merge them

I have a (Craft 3) matrix field with two different block types that each have a similar light switch field that I want to use to create anchor links on my page. I need to be able to test whether any ...
2
votes
1answer
39 views

Showing entries for light switch [duplicate]

So I have three light switches on my blog: 'featured', 'required reading' and 'skills'. I got the featured section to work with this code: {% for entry in craft.entries .section(['etiquette', '...
2
votes
1answer
33 views

Where to put where() for a query looking for a lightswitch field

Struggling with syntax here. I'm trying to query entries in the "resources" section, ordered by postDate desc, limit 1 and that also has the lightswitch "featured" as true. Here is what I have. ...
1
vote
2answers
46 views

If featured or latest entry

I'm trying to include different markup if a blog post is featured. This is done via a Lightswitch. If there's is no featured entry then the latest entry uses this different markup instead. The rest of ...
1
vote
1answer
33 views

Amending a lightswitch field value inside a matrix, from a plugin?

I have a plugin which is used to send a notification email when certain events happen. I need to watch the contents of a Matrix field attached to a User, and when a Lightswitch field inside the ...
0
votes
0answers
106 views

Expire field if last date in array is less than current date

I currently have a lightswitch which when turned on, enables me to input a list of dates which I would like to expire once they've passed the current date and once all dates have expired, turn off the ...
1
vote
0answers
43 views

Display entries linked from Matrix field according to the entries' structure and a light switch in the Matrix

In a channel (market), I have a Matrix field (market_products) with a Stucture-based Entries field (products) and a Lightswitch field (active/inactive). For each market, I need to create an ordered ...
2
votes
1answer
226 views

Can the Lightswitch field have a default 'on' setting?

I'm creating a new lightswitch field and adding it to an entry type in a section which already has dozens of entries. I want the lightswitch to be default set to 'on'. When I save the entry type with ...
1
vote
1answer
117 views

Entries lightswitch field within matrix

Is it possible to control if some content shows that's within a Matrix field if a lightswitch field on the entry is false. I expect not as you're inside the matrix loop. {% for block in entry....
0
votes
1answer
71 views

Hiding specific items from public

So I want to hide certain items if a user is not logged into the website. I already have a custom lightswitch field on each of the items but I'm not sure on how to write the code for it. Can anyone ...
4
votes
1answer
419 views

How can I query for entries that have one of two Lightswitch fields enabled?

I have two Lightswitch fields – lightswitchA and lightswitchB – and I need to pull all entries in a certain section, that have one or both of these fields enabled. Is it possible to execute such a ...
3
votes
2answers
205 views

When I flip the “Featured Entry” switch, disable it on other entries [duplicate]

Assuming I'm using a lightswitch to denote an entry as "Featured," how can I then disable that lightswitch on every other entry, so that no matter how many times I flip these switches only one entry ...
0
votes
1answer
233 views

Check in header file if lightswitch field is on

For a menu I have to check if a lightswitch field is on or not. The menu is in an extra header file. I've tried: {% if craft.entries.section('aboutus').lightswitch_field %}style="display: none;"{% ...
6
votes
2answers
434 views

Only allow one Lightswitch to be active at a time

I am working on a news section. There is a single featured news story so the lightswitch marked with ('1') displays the latest entry as the featured story. Below this the rest of the entries are ...
3
votes
1answer
139 views

How does Craft regard a Lightswitch field when it's set to Required in the Fields layout?

If I set a Lightswitch field as required, does that require it to be On? Is that valid at all? (Context: I'm using a Lightswitch in User fields to capture "I agree to the Terms & Conditions...", ...
4
votes
1answer
457 views

Can I add an enabled-by-default lightswitch field to existing entries?

I've created a lightswitch field that defaults to "On", and it works fine for new entries, but for all existing entries it is set to "Off". I'm keen to avoid having to manually go through all existing ...
0
votes
1answer
170 views

Problems Displaying Label and Instructions in Forms

I am trying to learn how to create plugins using craft and am having a small problem. On the templates/settings.html page I have the following code: {% import "_includes/forms" as forms %} {{ forms....
2
votes
2answers
335 views

How do I limit entries retrieved except those with a sticky lightswitch on the entry?

I have a list of "meetings" as entries and I want to show only the last two ordered by meetingDate, and show any other meetings marked as sticky, without doubling up. What I have so far is: {% set ...
7
votes
3answers
628 views

Change default status of entry publication (Lightswitch 'Status')

When I write an article and save it, I want to verify my text. I don't want publish my article immediately. If I'm tired, I sometimes forget to disable the Lightswitch 'Status'. So, how can I disable ...
1
vote
1answer
513 views

How can I get a lightswitch to work with order() in craft.entries?

I'm getting mixed results when using a lightswitch field together with order('RAND()') and I wonder if I'm doing something wrong. For example, this code gives me the correct results: craft.entries....
2
votes
1answer
335 views

How do I update the state of lightswitches reliably using checkboxes on a frontend user profile form?

I've got a frontend user profile form that is successfully setting the values of custom fields in the backend except for some lightswitch fields I've added to my user profiles. I have the following ...
5
votes
1answer
542 views

Updating a Lightswitch value not working via front-end

Everything looks OK but when I submit my form, field doesn't get updated. When the page reloads, the checkbox is still showing old state. <label>Some Option</label> <label><...
1
vote
1answer
569 views

Populate Lightswitch field from Frontend Entry Form

I have the following buttons on my frontend entry from (user editing one of their entries). The idea is to turn the lightswitch "on" (green) when entry is being marked as draft and "off" when ...
2
votes
1answer
1k views

Two different lightswitches to add class on body tag

I'm using a lightswitch field to add a class to my html document body-tag. The field is added to a section with a handle named "events". To make this happen, I do this in my _layout.html: {% if ...
3
votes
1answer
728 views

Using a Lightswitch to insert a class on a body's tag

I'm trying to use a Lightswitch field to insert a class on my body tag if the field is turned on. What would be a good Twig template code to do this? Edit 1: Thanks for answering, guys. I still ...
3
votes
1answer
453 views

Retrieving featured entry from a given category

This piece of code used to work to retrieve 1 featured (lightswitch) entry per category. {% for category in craft.categories %} {% set entries = craft.entries.find({ section: '...
19
votes
1answer
2k views

How do I check if a lightswitch field is false?

I have a Resources page and an archived Resources page made up of entries. I want to show all current resources on the main page (this list should not include the archived ones) and on the archived ...
8
votes
1answer
639 views

How do I maintain the on value with a lightswitch-field as a plugin setting?

I'm trying to use a lightswitch-field in a plugin-config. But for some reason it won't get saved. The lightswitch-field is always off. protected function defineSettings() { return array( ....