PHP code example of wpscholar / templatex

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

    

wpscholar / templatex example snippets




// Define your template paths
$templatePaths = [ __DIR__ . '/templates/' ];

// Create a new instance
$x = new wpscholar\TemplateX( $templatePaths );

// Set a template (relative to the template path)
$x->setTemplate( 'event.php' );

// Pass variables to your template
$x->setContext( [
    'title' => 'County Fair',
    'venue' => 'County Fairgrounds', 
] );

// Render the template
echo $x->render();


/**
 * @var \wpscholar\TemplateX $x
 */

>$x->is( $name, $value );
>

>$x->has( $name );
>

>$x->hasIn( $data, $name );
>

>$x->get( $name, $default );
>

>$x->getIn( $data, $name, $default );
>

>$x->set( $name, $value );
>

>$x->setIn( $data, $name, $value );
>

>$x->delete( $name );
>

>$x->load( $template, $vars, $withContext = true );
>

>$x->render();
>

>$x->setTemplate( $template );
>

>$x->setContext( $vars );
>

>$x->setTemplatePaths( $templatePaths );
>

>$x->addTemplatePath( $templatePath );
>