PHP code example of arif-rh / ci4-themes

1. Go to this page and download the library: Download arif-rh/ci4-themes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arif-rh / ci4-themes example snippets


 namespace Config;

class Adminlte extends \Arifrh\Themes\Config\Themes
{
	public $theme = 'Adminlte';
    
    // you can overide other properties as your need
} 

 

use Arifrh\Themes\Themes;

// inside your controller
    
$config = config('Adminlte'); // your custom theme config 
Themes::init($config);

addCSS(string|array $css_files)

// 1. using string (for single css file)

Themes::init()
    ->addCSS('style.css');

// 2. using string, separated by comma (for multiple css files)

Themes::init()
    ->addCSS('base.css, style.css');

// 3. using array (for single or multiple css files)

Themes::init()
    ->addCSS(['base.css', 'style.css']);

addJS(string|array $js_files)

Themes::init()
    ->addJS('script.js');

// or

Themes::init()
    ->addJS(['script.js', 'order.js']);

// or use with addCSS method

Themes::init()
    ->addCSS('checkout.css')
    ->addJS(['script.js', 'order.js']);

addInlineJS(string $js_scripts)

addExternalCSS(string|array $full_css_path)

addExternalJS(string|array $full_js_path)

loadPlugins(string|array $plugins)

/**
  * Registered Plugins
  * Format:
  * [
  *  'plugin_key_name' => [
  *   'js' => [...js_array]
  *   'css' => [...css_array]
  *  ]
  * ]
  */

public $plugins = [
		'bootbox' => [
			'js' => [
				'bootbox/bootbox-en.min.js'
			]
		]
	];

Themes::init()
    ->loadPlugins('bootbox');

// or

Themes::init()
    ->loadPlugins('bootbox, datatable');

// or

Themes::init()
    ->loadPlugins(['bootbox', 'select2', 'datatable']);

useFullTemplate(boolean $use_full_template = true)

// assume your login view has full html and body tags

Themes::init()->useFullTemplate();
Themes::render('login')

setHeader(string $header_name)

// assume that you have another-header.php in your active theme folder

Themes::init()
    ->setHeader('another-header');

setTemplate(string $template_name)

// assume that you have another-template.php in your active theme folder

Themes::init()
    ->setHeader('another-template');

setFooter(string $footer_name)

// assume that you have another-footer.php in your active theme folder

Themes::init()
    ->setFooter('another-footer');

setTheme(string $theme_name)

// assume that you have frontend theme

Themes::init()
    ->setTheme('frontend');

render(string $viewPath = null, array $data = array())

// for example, default welcome_view in CodeIgniter4 can be render like this
// we useFullTemplate because welcome_message contains full html and body tags

Themes::init()->useFullTemplate();  
Themes::render('welcome_message');

// you can manage your header, main template and footer in theme
// then you can render any view like this

Themes::render('dashboard')

 Arifrh\Themes\Themes::renderCSS(); 

 Arifrh\Themes\Themes::renderJS(); 

setPageTitle(string $page_title)
+HTML
<title><?= $page_title 

setVar($key, $value)

Themes::init()->setVar('page_title', 'Welcome Page');

// same as

Themes::init()->setVar(['page_title' => 'Welcome Page']);

// same as

Themes::render('view_name', ['page_title' => 'Welcome Page']);

init(\Config\Themes $config = null)