Viewing 3 reply threads
  • Author
    Posts
    • #9111
      moshemo
      Member

      I have the following function which returns a list of the top level Menu Items:

      `
      function get_top_level_menu_items()
      {
      global $menu;

      $menu_zero = array_column($menu, 0);
      foreach (array_keys($menu_zero, ”, true) as $key) {
      unset($menu_zero[$key]);
      }

      return $menu_zero;
      }
      `

      What I would like to do is create a select box, checkbox (or something similar) that is populated by this list of menu items. I’m not sure, though, how to do that. How can I access the $menu_zero array inside of piklist?

    • #9112
      Steve
      Keymaster

      Since that function is already returning an array, it’s super easy:

      
      piklist('field', array(
        'type' => 'select'
        ,'field' => 'top_level_menu'
        ,'label' => 'Choose Menu'
        ,'choices' => get_top_level_menu_items()
      ));
      
    • #9113
      moshemo
      Member

      Thanks – I’ll remember that for the future. In the meantime, I got it to work by removing the function and just using the code in the settings page — like this:

      `
      global $menu;

      $menu_zero = array_column($menu, 0);
      foreach (array_keys($menu_zero, ”, true) as $key) {
      unset($menu_zero[$key]);
      }

      piklist(‘field’, array(
      ‘type’ => ‘select’
      ,’field’ => ‘top_level_menu’
      ,’label’ => ‘Choose Menu’
      ,’choices’ => $menu_zero
      ));
      `

    • #9114
      Steve
      Keymaster

      That works too!

      Closing this ticket.

Viewing 3 reply threads
  • The topic ‘Accessing Global Variable in Piklist’ is closed to new replies.