double_trouble
double_trouble

Reputation: 1

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

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?

Upvotes: 0

Views: 146

Answers (1)

Hardik Satasiya
Hardik Satasiya

Reputation: 9693

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.

Upvotes: 1

Related Questions