prepareItemString (function)

Last updated: Fri, May 26, 2023 9:54 am
Return to Knowledgebase

Purpose

The prepareItemString function in UserSpice is a custom function used to generate an HTML string representing a menu item based on the provided menu item data.

Location

users/helpers/menus.php

Parameters

# Parameter Data Type Required Description
1 $menuItem array Yes The menu item data. This array contains properties such as label, link, and icon_class that define the menu item.
2 $user_id integer Yes The user ID. This parameter is used to check user permissions for certain menu items.

Returns

Data Type Description of Returned Data
string The function returns a string representing the HTML markup for the menu item.

Further Documentation:

$menuItem = [
'label' => 'Home',
'link' => 'index.php',
'icon_class' => 'fa fa-home',
// Other menu item properties
];

$user_id = 1;

// Get the HTML string representing the menu item
$itemString = prepareItemString($menuItem, $user_id);

echo $itemString;


In the example above, the prepareItemString function is called with the $menuItem array and the $user_id as arguments. The $menuItem array contains properties such as label, link, and icon_class that define the menu item. The $user_id parameter is used to check user permissions for certain menu items.

The function generates an HTML string representing the menu item based on the provided data. The generated string includes the menu item's label, link, and icon class. The resulting HTML string can be outputted to display the menu item in the desired location.