PHP code example of awesome9 / templates

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

    

awesome9 / templates example snippets


Awesome9\Templates\Storage::get()
	->set_basedir( dirname( __FILE__ ) )
	->set_baseurl( plugins_url( __FILE__ ) );

Awesome9\Templates\Storage::get()->add( 'admin', 'admin/templates' );
Awesome9\Templates\Storage::get()->add( 'frontend', 'frontend/templates' );

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

$template->render();

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

Awesome9\Templates\Storage::get()->set_for_theme( 'templates', 'my-plugin' );

$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 Awesome9\Templates\Template(
	$storage_name = 'frontend',
	$template_name = 'profile',
	$variables  = [
		'var_key' => $var_value,
	]
);

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

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

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

my-plugin/
├── templates/
│   ├── notice.php
│   └── profile.php

some-theme/
├── my-plugin/
│   ├── notice.php
│   └── settings.php
get_vars()