Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [lightswitch]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
41 views

Search lightswitch field with disabled value

I want to exclude some entires from search, so I add a field hideFromSearch and enable Use this field’s values as search keywords It works when I search like Entry::find()->search('hideFromSearch::...
Thomas's user avatar
  • 69
1 vote
1 answer
449 views

Filtering by lightswitch fields

Bit of an unusual one and sure must be missing something but know if we have a defined lightswitch field we want to filter against it can quite easily be done so like this: {{ craft.products().myField(...
Cole Henley's user avatar
  • 1,741
1 vote
1 answer
116 views

Within the CP, how can I filter the listed Entries based on a Lightswitch field value?

I tried these kind of searches in the CP search field (on top of the Entry list): fieldHandle:true / fieldHandle:false fieldHandle:1 / fieldHandle:0 fieldHandle:* / -fieldHandle:* fieldHandle:not 1 / ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
52 views

Hide navigation from one entry but not others

I am looking to hide the main navigation for entries that have the lightswitch 'showMainNavigation' disabled. The problem I am facing is when I disable for one entry, the navigation is hidden for all ...
user9494's user avatar
1 vote
1 answer
89 views

Show entries by a certain category AND certain lightswitch

Just thinking of an easy way for the user to manage products on a site. Therefore is it possible to display entries by a category and a lightswitch toggle? IE. Category selected is Photocopiers and ...
moondawg's user avatar
  • 333
1 vote
1 answer
66 views

Show/display entries next/prev except entries with lightswitch field active

I have projects on my portfolio that link to each other. I'm currently using previous and next links. This is what my code looks like {# Set parameters for prev/next elements list #} {% set params = ...
mateostabio's user avatar
3 votes
1 answer
1k views

How to query/filter by the value of a lightswitch

In my news entries, I have a lightswitch field with the handle 'pinned'. I'm trying to query my news section for both pinned and unpinned news entries (true or false essentially), but I can't get ...
Jim's user avatar
  • 139
1 vote
1 answer
61 views

How to include a lightswitch for each related entry in the source element of a relationship

I have a Services section in which I keep a related entry field for News. (News by Service) The News items to be displayed for each service are selected in a "News" entries field in the Service entry. ...
Jim's user avatar
  • 139
1 vote
1 answer
209 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 ...
artmem's user avatar
  • 1,022
2 votes
1 answer
280 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', '...
Mforeman's user avatar
2 votes
1 answer
179 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. ...
Danielle Frappier's user avatar
1 vote
2 answers
182 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 ...
sarah3585's user avatar
  • 899
2 votes
1 answer
54 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 ...
Matt Wilcox's user avatar
  • 3,209
1 vote
0 answers
75 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 ...
Shanan Galligan's user avatar
4 votes
2 answers
541 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 ...
Adam Menczykowski's user avatar
1 vote
1 answer
176 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....
sarah3585's user avatar
  • 899
0 votes
1 answer
119 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 ...
JustinTheeDude's user avatar
3 votes
1 answer
822 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 ...
Mats Mikkel Rummelhoff's user avatar
3 votes
2 answers
343 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 ...
jasonetco's user avatar
  • 141
0 votes
1 answer
546 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;"{% ...
Jonathan Schiffner's user avatar
5 votes
2 answers
545 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 ...
itisconor's user avatar
3 votes
1 answer
161 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...", ...
Mark J. Reeves's user avatar
5 votes
1 answer
739 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 ...
Nick F's user avatar
  • 1,215
0 votes
1 answer
281 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....
Moshe's user avatar
  • 239
2 votes
2 answers
402 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 ...
Jack McKenzie's user avatar
7 votes
4 answers
947 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 ...
Tho SABATTIE ilicos's user avatar
1 vote
1 answer
607 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....
naboovalley's user avatar
  • 2,844
3 votes
1 answer
543 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 ...
Adam Snetman's user avatar
6 votes
1 answer
811 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><...
Sean Delaney's user avatar
1 vote
1 answer
876 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 ...
David A McInnis's user avatar
2 votes
1 answer
2k 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 ...
osh's user avatar
  • 615
3 votes
1 answer
929 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 ...
osh's user avatar
  • 615
3 votes
1 answer
522 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: '...
imnotsure's user avatar
  • 199
19 votes
1 answer
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 ...
Carlos's user avatar
  • 193
8 votes
1 answer
867 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( ....
Victor's user avatar
  • 8,396