How to pass parameters and based on them create a condition in markup?

129 views Asked by At

I'm a newbie. How to pass parameters and based on them create a condition in markup? I have such a component

{% component 'demoTodo' %}

but I want to use it in two variations, if mobile = true, then another markup, if false another {% component 'demoTodo' mobile=true %} or {% component 'demoTodo' mobile=false %}

{% if mobile == true %}
  ...
{% else %
...
{% endif %}

How can this be done?

1

There are 1 answers

0
Hardik Satasiya On

You need to pass component property and retrieve it in onRender method and again need to pass it to markup.

You can follow this process to get mobile variable to your markup.

Your page markup where you include component with property mobile

{% component 'demoTodo' mobile=true|false %}

Inside your demoTodo component php code

function onRender() {
   $this->page['mobile'] = $this->property('mobile');
}

in your component's default.htm markup nor mobile variable will be available

{% if mobile == true %}
  ...
{% else %
  ...
{% endif %}

if any doubt please comment.