Show group of elements based on condition

Fastserv

Member
Hi

I made a custom detail view and call every element in the template like this:

PHP:
<?php $this->element = $this->elements['preis']; echo $this->loadTemplate('element'); ?>

Is it possible to show a group of elements based on conditions?
Maybe something like that:
PHP:
<?php if ($this->element = $this->elements['preis'] > '0') : ?>
<?php $this->element = $this->elements['preis']; echo $this->loadTemplate('element'); ?>
<?php $this->element = $this->elements['waehrung']; echo $this->loadTemplate('element'); ?>
<?php else;?>
something else
<?php endif;?>

Any help is greatly appreciated.

Stefan
 
Yes. Easiest way to get element data in a form template is ...

PHP:
$foo = $this->getModel()->getElementData('yourtable___foo', true);

The 'true' argument tells us to hand you the 'raw' value. If you want the formatted value, just omit that second arg, or set it to false.

So in your case ...

PHP:
if ((int) $this->getModel()->getElementData('yourtable___preis', true) > 1) {
   ... do something ...
}
else {
   ... do something else ...
}

Replace 'yourtable' with your table name, i.e. so you have the "full element name" as shown in the main list of Elements on the backend.

Also note in this case, we're casting the value getElementData() returns to (int), so we can do a simple arithmetic > test.

I'm assuming you'll need the raw value, as this will give you the "value" rather than the "label" for things like dropdowns, joins, etc.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top