0

How can use Checkbox content type in block content type and how can i get values of checkboxes from block content type in Sulu-minimal?

<block name="block_basic_guarantees" default-type="text" minOccurs="0">
<meta>enter code here
<title lang="en">Garanties de base</title> 
</meta> 
<types> 
<type name="Boolean">
<meta>
<title lang="en">Button</title>
<title lang="de">Button</title>
</meta>
<properties>   
<property name="formule-lessentiel" type="checkbox">
<meta>
<title lang="en">Formule L’ESSENTIEL 1</title>
</meta> 
<params>
<param name="type" value="checkbox"/>
</params>
</property>  
<property name="formule-confort" type="checkbox">
<meta>
<title lang="en">Formule CONFORT</title>
</meta> 
<params>
<param name="type" value="checkbox"/>
</params>
</property> 
<property name="formule-letendue" type="checkbox">
<meta>
<title lang="en">Formule L’ETENDUE</title>
</meta> 
<params>
<param name="type" value="checkbox"/>
</params>
</property> 
<property name="formule-surmesure" type="checkbox">
<meta>
<title lang="en">Formule LE SUR-MESURE</title>
</meta> 
<params>
<param name="type" value="checkbox"/>
</params>
</property> 
</properties>
</type> 
</types>
</block>  

I have tried this,

{% set basic_guarantees = content.block_basic_guarantees %} 
{% for guarante in basic_guarantees %}
      {{ guarante.formule-lessentiel }}
      {{ guarante.formule-confort}}
      {{ guarante.formule-letendue }}
      {{ guarante.formule-surmesure }}
{% endfor %}  

I want result if checkbox is checked then, true or 1 otherwise if not checked then, false or 0.

  • 1
    Have you tried avoiding the dash in the property name? What if you name them e.g. `formule_lessential` and access it via `{{ guarante.formule_lessentiel }}`? – Daniel Rotter May 10 '19 at 08:48

1 Answers1

1

As danrot mention the problem here is the dash in your property name. So if you write:

{{ guarante.formule-lessentiel }}

Its the same as you would write:

{{ guarante.formule - lessentiel }}

To access a variable with dash in it you can do:

{{ guarante['formule-lessentiel'] }}

or

{{ attribute(guarante, 'formule-lessentiel') }}

Which is very ugly so as danrot recommended use underlines instead.

Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42