Milk Admin

Theme

The theme class stores and returns data.
This data is used to render the theme.
The data has the characteristic of always being stored in arrays so set('a',1) and set('a',2) will return get('a') = [1,2]. To clear the data just pass NULL as value.

Functions

Theme::set($path, $data)

Stores a new variable inside an array to use in the theme.

Theme::get($path, $default = null)

Extracts the last value of the array

If you want to modify the data you can do it with a 'theme_get_{path}' hook.

Theme::getAll($path)

Returns all the values ​​stored in a path.

If you want to modify the data you can do it with a 'theme_get_{path}' hook.

Hooks::set('theme_get_sidebar.links', function($data) { 
$data[0]['title'] = 'User list'; 
return $data;
});

Theme::has($path)

Checks whether a value exists in a path.

Theme::delete($path)

Delete a variable.

Theme::for($path)

Iterates an array of values. A generator returns.

foreach (Theme::for('myvars') as $var) { 
echo $var; 
}

Theme::check($path, $type)

Check the data type

Variables used in the theme

Here are listed the variables used in the theme and how they are used, to set them always use Theme::set()

Theme::for('content')

The content of the page.

Theme::for('styles')

Contains the complete url of the css files to load.

Theme::for('javascript')

Contains the complete url of the js files to load. The scripts are loaded at the bottom of the page

Route::set('mypage', function() { 
Theme::set('javascript', Route::url().'/Modules/mypage/assets/mypage.js'); 
// ...
});
Theme::get('footer.first');

The html code to insert before the footer.

Theme::get('footer.text', '© '.date('Y').' Milk Admin')

The copyright.

Theme::get('header.lang','en')

The language of the page.

Theme::get('header.charset','utf-8')

The charset of the page.

Theme::get('header.title', 'MILK ADMIN')

The title of the page.

Theme::get('header.custom')

The custom code to insert inside of the head.

Theme::get('header.links')

The horizontal menu. ['url'=>'', 'title'=>'', 'icon'=>'']

Theme::get('site.title')

The title of the site.

Theme::get('header.top-left')

The text of the breadcrumbs.

Theme::get('sidebar.links')

The menu items. ['url'=>'', 'title'=>'', 'icon'=>'', 'order'=>10]

 
Theme::set('sidebar.links', [ 
'url' => Route::url('?page=docs&action=Developer/GettingStarted/introduction'), 
'title' => 'Guide', 
'icon' =>'bi bi-journals']); 

You can find the icons on https://icons.getbootstrap.com/

Theme::get('site.title')

The site title returns. Default Config::get('site-title')

Theme::get('header.title')

The page title returns. Default Config::get('site-title')

How to Add a new menu item

Theme::set('sidebar.links',
['url' => Route::url('?page=auth&action=user-list'), 'title' => 'Users', 'icon' => 'bi bi-people-fill']);
// horizontal menu
Theme::set('header.links', ['url' => Route::url('?page=auth&action=logout'), 'title' => 'Logout', 'icon' => 'bi bi-box-arrow-right']
);

How to Manually Select a Sidebar Menu Item

By default, the sidebar automatically selects menu items based on the current page URL. You can bypass this automatic selection and manually select a specific menu item using Theme::set('sidebar.selected', ...).

Select by URL

// This will select the menu item with this exact URL
Theme::set('sidebar.selected', Route::url('?page=auth&action=user-list'));

Select by Title

// This will select the menu item with this exact title
Theme::set('sidebar.selected', 'Users');

Example: Force a menu selection regardless of current page

// Even if the current page is ?page=dashboard,
// the "Settings" menu will be highlighted
Theme::set('sidebar.selected', 'Settings');

Note: When sidebar.selected is set, the automatic URL comparison is completely bypassed. Only the menu item matching the specified URL or title will be highlighted.

How to add an image

<img src="<?php echo Get::uriPath(THEME_URL.'/Assets/logo-big.webp') ;?>" alt="test" class="resized-logo">

<img src="<?php echo Get::uriPath(Route::url().'/Modules/my-module/assets/img.jpg') ;?>" alt="test" class="resized-logo">

Loading...