Categories > TinyButStrong general >

Conditional display with array

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Michael Frey
Date: 2016-05-16
Time: 11:00

Conditional display with array

I have an array which I merge as a field.

$rights = array('cms', 'reports');
$TBS->MergeField('rights', $rights);

Then on my view I have several links. I only want to show the link IF the user has the right in his array. How would I achieve this?

<a href="/cms">CMS</a>
<a href="/reports">Reports</a>
<a href="/finances">Finances</a>

Using MergeBlock is not really an option I want to go with, because my actual links are much more complicated and contain custom hardcoded data and styles.
By: Skrol29
Date: 2016-05-20
Time: 15:44

Re: Conditional display with array

A solution :

PHP
$rights = array(
   'cms' => 1,
   'reports' => 1,
);
$TBS->MergeField('rights', $rights);

Template
<a href="/cms">     CMS      [right.cms;noerr;magnet=a;ope=minv]</a>
<a href="/reports"> Reports  [right.reports;noerr;magnet=a;ope=minv]</a>
<a href="/finances">Finances [right.cms;noerr;magnet=a;ope=minv]</a>

Parameter "noerr" return empty string ('') if the item is not found.
Parameter "ope=minv" makes the TBS fields to be never displayed.

See http://www.tinybutstrong.com/manual.php#html_field_prm_ope

Please not that a MergeField() is slower than a MergeBlock().
By: Michael Frey
Date: 2016-05-20
Time: 22:19

Re: Conditional display with array

Thank you. Exactly what I wanted. Didn't know about the ope part.