I got some optional url parameters on a number field. In that way the visitor can filter the entries.

I got in my datasource: equal to or greater than {$url-weight:0}

So if the visitor choose 1000 all weights above 1000 and 1000 will show.

But the field 'weight' is optional for the client. So I need also to filter when weight is empty for a show all option.


Returns the empty values but it seems I can't combine both filters, like:

equal to or greater than {$url-weight:0}, regexp:{$url-dynamic-load:}

I'm stuck.

I'm still stuck. A regexp maybe can work this out, but I doubt because if I got it right it is mysql regexp and don't know if that has conditional regexp. At least I tried a lot and nothing works. An empty field seems to be totally ignored with url parameters.

So I'm afraid that

  • Or I have to fill all inputs at least with a zero and I exclude entries with 0 from the html in the template
  • Or I make use of the reflection field and replace the empty values with a xslt utility so the client has not the hassle

In the past when I have done things like this, I always made sure there was a default value that would work in the urls. So anytime there is a link or a form creating a dynamic url it would fill in a base value / default value for each URL VAR.

So passing 0 would work for the weight in this case.

If someone links to the page without the url vars you can set up template vars to fill in as the defaults so for URL-weight I might put xsl variable "temp-weight" and in your datasource

equal to or greater than {$url-weight:$temp-weight}

You just need to make sure when an url is generated it has a default value for each url var if none is specified.

If there is a better way to have missing url vars I too would like to know!

As you say, there is a way to set a default. A datasource parameter filter can have a value with :value. {$url-weight:value} that fills the gap.

But there is no really need for an extra variable. Except that the suggested extra variable is an excellent solution to make it more dynamic because it is in the template and can be set by any value depending on url and loaded datasources for example.

But the hardest part I'm knockin my head on is that entries where a field is empty are completely ignored by every filter. And we are talking here about hundreds and hundreds entries. Some automation could be here very handy.

Ok so in the datasource you want to filter for all items

equal to or greater than {$url-weight:0} OR are emtpy

I found this try "sql: NULL"

equal to or greater than {$url-weight:0}, sql: NULL

edit: reference

Thanks Jeff. But you can't combine normal filters with sql filters as far as I can see. That was mentioned by Brendo already in 2011:

I think that isn't change since.

if it's either or, if you're willing to customize your datasource you can do the following.

modify the $dsPARAMFIELDS and split your existing one into two parameters. Customize the Execute funciton. and do the following:

check weather your weight is set param is empty, if yes, set the dsparam for the field equal to the regexp option. If no use the weight one.

Important I recommend you'd use string named params, for ease to remember and then important to unset these params before calling the parent execute function. I do this at times when I need to choose / modify params according to the values, and works like a charm.

That sounds interesting Jonathan. Can you provide an example?

I have to customize the datasource for sorting, so that is not the problem. But I can't find the $dsPARAMFIELDS

Sorry mistake meant $dsPARAMFILTERS

    public $dsParamFILTERS = array(
            'weight' => 'equal to or greater than {$url-weight:0}',
            'dynamic-load' => 'regexp:{$url-dynamic-load:}',

Then check weight and dynamic load, if they're filled as expected unset the related variables and set the right value

        $this->dsParamFILTERS['123'] = $this->dsParamFILTERS['dynamic-load']

Note it's just an example there's a bit more work you'd need to do.

Sorry I also make a mistake in my question

equal to or greater than {$url-weight:0}, regexp:{$url-dynamic-load:}

Must be off course the same url-param, thus

equal to or greater than {$url-dynamic-load:0}, regexp:{$url-dynamic-load:}

In that way I would be better with an if $url-dynamic-load exist then use this is filter else use that.

But I'm far from a php coder so I don't know where to place an if...else statement.

ah ok sure. you basically want to check if $url-dynamic-load is set. If it is set you want to use the greater then otherwuse you want to use the regexp?

If that's so... how would you use a regexp of an empty variable? Or is it the otherway around?

Or is it just you want to get all things with equal to or greater than 0 ? I think there's something somewhat wrong with the logic... or I'm otherwise misunderstanding. If I understand that I can give you the complete snippet.

Indeed I want to check if $url-dynamic-load is set. If it isn't then there is no need for filtering.

Use case:

/products/ > shows all products (including those with no static load)

/products&static-load=500 > shows all products with a static load from 500 and greater

When I place in the construct or execute function an unset for the filter gives the result. But I can't figure out how to find the url param values ($url-dynamic-load)

Applaud, finally got it (I really need to go to the php school :-)) But the following code in the execute function solved my problem.

if (strlen($this->_env['param']['url-static-load']) == 0) {

Thanks Jonathan for pointing me into the right directions

Yep that's one way to do it. But it would be neater if you do the following.

public $dsParamFILTERS = array(
        'static-load' => '{$url-static-load:}',

if (isset($this->dsParamFILTERS['static-load])){
    $this->dsParamFILTERS['441'] = "equal to or greater than " . $this->dsParamFILTERS['static-load];

As long as it's in the execute function you wouldn't have to check environment variables etc the param filters will be pre-populated with what you need :) sorry for the late reply btw.

Oh great Im glad you figured that out. I will be book marking this for the future :)

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