if statement inside the getCategories

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 30, 2019   (RSS)

By Zicky - December 30, 2019

Howdy folks,

I'm trying to add an if statement inside the getCategories as seen below. This feature would add a css style to the the ul of a menu - if a checkbox in the site's settings is checked off. Can anyone tell me if this is possible and what I need to do to the code to get it functioning?

list($aboutRecords, $selectedCategory) = getCategories(array(
    'tableName'   => 'about',
    'categoryFormat' => 'showall',
    if ($settingsRecord['menu_1_tier'] =='1') { 'ulAttributes' => 'class="vertical menu"', }

Thanks, Zicky

By daniel - December 30, 2019

Hi Zicky,

It's certainly possible to modify an options array based on an if condition - it just requires breaking things down into a few steps. First, you'll want to create the options array as a variable, then use the if condition to modify that array variable, and finally pass that array variable to the functions. That would look something like this:

$categoryOptions = array(
  'tableName'   => 'about',
  'categoryFormat' => 'showall',

if ($settingsRecord['menu_1_tier'] =='1') {
  $categoryOptions['ulAttributes'] = 'class="vertical menu"'; 

list($aboutRecords, $selectedCategory) = getCategories($categoryOptions);

The above hasn't been tested so you may need to make some adjustments to get it to work in your code, but hopefully, this gets you pointed in the right direction. Let me know if you have any questions!


Technical Lead