Search

The documentation suggests that using the comma results in a union operator in a DS filter, but only they first value is coming out in my query. Is this just me? I tried filtering by a checkbox with “yes, no” as the filter value. Not very useful that’s true - my aim was to include drafts only if a parameter is set.

I not sure that would work as the checkbox will be given a value of no if yes is not set (so it’ll always be set), so it wouldn’t make sense to use the union operator on the checkbox field.

There is nothing you can do really to filter a datasource if x field has a value using a single datasource AFAIK. You could get around it using two datasources, one to output x fields as a param, and the other to use that param to filter the x field by though I think :)

I tried filtering by a checkbox with “yes, no” as the filter value.

Filtering a checkbox with yes, no will return true for all your entries as a checkbox returns either yes (“I’m checked.”) or no (“I’m not checked.”). If you use a checkbox for highlighting drafts (checked = draft), you should just filter with yes to return drafts or with no to return published entries. Leaving the filter empty or using yes, no will return all entries.

Yes, but when I filter by “yes, no” I would expect all the entries to be in the result, but actually only those with “yes” are output.

This behaviour might have two reasons:

  • It’s either a bug in the checkbox field which does not save no values (= unselected)
  • or you added your checkbox field to a section with existing entries which now seem to have unselected checkboxes but don’t not have a corresponding no value saved in the database yet.

It doesn’t seem to be either of those. I checked with select * from sym_entries_data_33; and all entries have “yes” or “no” in the value column.

So the problem seems to be in the union of the two options unfortunately. Some simple logging in datasource.section.php would suggest that the second option is making it into the filter array, but not into the query.

I mentioned it before, but I’ll say it again. The checkbox field doesn’t support union operations at all, so there is no way that yes, no would select both lots of entries.

In that case I would suggest the documentation could use a touch-up to make it clear that not fields are supported in the same way.

Never mind, I should be able to do what I wanted in the XSL, was just attempting to apply the KISS principle.

I still am not sure of what you are trying to accomplish m_onkey. In your original post you mention you want to show some drafts in the entries output.

A checkbox might not be the best solution for that, as it’s really meant boolean states, ie. true/false, yes/no, not yes/no/maybe. Perhaps a Select Box would more suit your application?

You could give it the values of Publish, Force Publish, Draft and then in your datasource filter when it’s set to Publish or Force Publish?

The reason the Checkbox field doesn’t support unions is because then the filter would not make sense. If you were to filter by checkbox where it’s value is yes or no, you would get the same result as if you didn’t filter by the checkbox field at all!

I was trying to filter by “yes” in most circumstances, and “yes, no” in others. I thought the filtering was more sophisticated than it is!

Yes, No is the same as not filtering at all though as all checkbox fields will have the value Yes or No.

Yes, No is the same as not filtering at all though as all checkbox fields will have the value Yes or No.

It is. So really yes, no should work as a Data Source filter. It works for Text input fields, and Select Box fields, so I would expect it to work for a Checkbox field (no matter how useless it might appear). If a user has a mental model about how filters work, and a native field breaks that model, then it feels like a bug.

Yes, No is the same as not filtering at all though as all checkbox fields will have the value Yes or No.

It should be the same, but it isn’t - “yes, no” is the same as filtering with “yes”.

My aim was to do something along the lines of if a certain condition is met, apply "yes,no" which is the equivalent of not filtering, otherwise apply "yes". The condition would ideally be that the user is logged in and the URL param drafts is set. I know that you can achieve similar in the XSL but it complicates the XSL, and I expected this to work.

As a first example, my filter was yes, {$url-liveview:yes}. Admittedly this doesn’t have user authentication but better than nothing.

The idea is that I don’t want to have a separate drafts page, I want an author to be able to preview changes in-situ. For example, if the page has a list of forthcoming events I want the author to be able to create an event as a draft, preview in-site, then publish if they are happy.

Thanks for your comments Nick.

I finally managed to get the integration branch working (new to git) and test Nick’s fix - works a treat!

I can now filter my datasource with {$url-liveonly:yes}, yes, meaning that if I add ?liveonly=no to the URL I can see the drafts as well as the published entries. In turn this means that I don’t need to overcomplicate the XSL.

The big drawback is that I don’t think I can check if the user is logged in. This isn’t a problem for my two current projects, if someone is determined to see the drafts then they must be very bored!

Thanks again Nick!

You can check if a user is logged in to Symphony by looking at the $cookie-usermame parameter provided to your XSLT. So you could check for this at the XSLT level perhaps.

The custom Login Info event that comes with the default ensemble/workspace when installing Symphony adds more information about the logged-in user to your XML.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details