PHP code example of wpify / templates

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

    

wpify / templates example snippets


use Wpify\Templates\WordPressTemplates;

// Initialize the templates
$template = new WordPressTemplates(
	array(
		plugin_dir_path( __FILE__ ) . 'templates', // path to template files in plugin
		trailingslashit( get_template_directory() ) . 'my-plugin', // path to template files in current theme 
	), 
);

// Print the html to frontend 
$template->print( 'my-template', 'test', array( 'some-args' => 'test' ) );

// Return the html
$html = $template->render( 'my-template', 'test', array( 'some-args' => 'test' ) );

use Wpify\Templates\TwigTemplates;

// Initialize the templates
$template = new TwigTemplates(
	array(
		plugin_dir_path( __FILE__ ) . 'templates', // path to template files in plugin
		get_template_directory() . 'my-plugin', // path to template files in current theme 
	),
	array(
		'integrate' => true, // Allows twig templates for the current theme
		'debug'     => true, // Enable twig debug
		'functions' => array( // Register custom functions.
			'test_function' => function() {
				echo 'TEST';
			},
		),
		'filters' => array( // Register custom filters.
			'test_filter' => function( $value ) {
				echo 'TEST:' . $value;
			},
		),
		'globals' => array( // Register global variables.
			'global_variable' => 'some value',
		),
		'namespaces' => array(
			'blocks' => get_template_directory() . '/blocks',
		),
	)
);

// Print the html to frontend 
$template->print( 'my-template', 'test', array( 'some-args' => 'test' ) );

// Return the html
$html = $template->render( 'my-template', 'test', array( 'some-args' => 'test' ) );