2

I want to render parameters if they exist but can't find a way of correctly displaying it and keep getting An opened parenthesis is not properly closed. Unexpected token "punctuation" of value ":" ("punctuation" expected with value ")")

where

{% setcontent records = 'properties' where
{filter:search_term,
((classification) ? ('classification':classification):(''))
} printquery  %}
damunga
  • 95
  • 4
  • 11

1 Answers1

2

To use it inside Bolt CMS, first define your options and then pass that to Bolt CMS

{% set options = { filter: search_term , } %}
{% if classification is defined and classification|trim != '' %}
    {% set options = options|merge({classification:classification,}) %}
{% endif %}

{% setcontent records = 'properties' where options printquery  %}

After rereading your question you are probably looking for something like this,

{% set records %}
'properties' where { 
    filter : '{{ search_term }}',
    classification: '{{ classification is defined ? classification : '' }}',
} printquery  %}
{% endset %}

{{ records }}

However using the filter default here is more suited than using the ternary operator,

{% set records %}
'properties' where { 
    filter : '{{ search_term }}',
    classification: '{{ classification|default('') }}',
} printquery  %}
{% endset %}

{{ records }}

demo


To omit properties you would use the following,

{% set records %}
'properties' where { 
    filter : '{{ search_term }}',
    {% if classification is defined and classification|trim != '' %}classification: '{{ classification }}',{% endif %}
} printquery  %}
{% endset %}

DarkBee
  • 16,592
  • 6
  • 46
  • 58
  • Thank you its much clear. But I wanted to see if i could do `classification: '{{ classification|default('') }}` But as `{{classification:classification|default('') }}` – damunga Dec 11 '18 at 06:19
  • No, because the `:` is used in created arrays e.g, `{% set foo = { classification: classifcation|default(''), } %}` – DarkBee Dec 11 '18 at 06:35
  • Ok, I've tried the same. But since if var `classification` doesnt exists if becomes empty, my bolt query will search for ``bolt_properties`.`classification` = ''` which will return empty. Thus i wanted to search by classification if it exists as a get param – damunga Dec 11 '18 at 06:47
  • See editted answer if you want to omit non-existing/empty filters – DarkBee Dec 11 '18 at 06:58
  • Thank you. I just checked i'm using Bolt CMS. I cant query using {%set%} but only {%setcontent%} – damunga Dec 11 '18 at 07:45
  • See last edit - Did not know `{% setcontent ..` was a valid node – DarkBee Dec 11 '18 at 07:57
  • Thank you! it makes sense now. – damunga Dec 11 '18 at 12:50