PHP code example of micropackage / templates

1. Go to this page and download the library: Download micropackage/templates 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/ */

    

micropackage / templates example snippets


Micropackage\Templates\Storage::add( 'admin', $plugin_dir . '/admin/templates' );
Micropackage\Templates\Storage::add( 'frontend', $plugin_dir . '/frontend/templates' );

$template = new Micropackage\Templates\Template( 'frontend', 'profile', [
	'user_name' => $user_name,
	'posts'     => get_posts( [ 'author' => $user_id ] ),
] );

$template->render();

<p>Howdy,  $this->the( 'user_name' ); 

$this->the( 'var_name' ); // Prints the value.
$var_name = $this->get( 'var_name' ); // Gets the value.

$the( 'var_name' ); // Prints the value.
$var_name = $get( 'var_name' ); // Gets the value.

$the( 'var_name', 'Default val' );
$var_name = $get( 'var_name', 'Default val' );

$template = new Micropackage\Templates\Template(
	$storage_name = 'frontend',
	$template_name = 'profile',
	$variables  = [
		'var_key' => $var_value,
	]
);

// Print the template.
Micropackage\Templates\template( $storage_name, $template_name, $variables );

// Get the template output.
Micropackage\Templates\get_template( $storage_name, $template_name, $variables );

my-plugin/
├── admin/
│   └── templates/
│      ├── notice.php
│      └── settings.php
└── frontend/
    └── templates/
       ├── profile.php
       └── welcome.php
get_vars()