PHP code example of italystrap / view

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

    

italystrap / view example snippets


$finder = new \ItalyStrap\View\ViewFinder();

$finder->in( 'full/path/to/the/views/' );
//or
$finder->in( ['full/path/to/the/views/','full/path/to/the/views/'] );


$view = new \ItalyStrap\View\View( $finder );

$view->render( 'slug', $data ); // Data could be the type of: string|int|array|object
// Or
$view->render( ['slug'], $data );
// Or
$view->render( ['slug', 'name'], $data );
// Or
$view->render( ['slug', 'name', 'subName'], $data );

// It will search in the root of your theme slug-name.php -> slug.php
\ItalyStrap\View\get_template_part( 'slug', 'name', $data );

// Or

use ItalyStrap\View;

// theme_path/slug-name.php
// theme_path/slug.php
get_template_part( 'slug', 'name', $data );

// theme_path/slug-slug1-name.php
// theme_path/slug-name.php
// theme_path/slug.php
get_template_part( ['slug', 'slug1'], 'name', $data );


\add_filter( 'italystrap_view_get_template_part_directories', function( array $dirs ) {
    // Add here your logic for dirs
    // For example you can add subdirs or remove dirs
    // You can add directories for languages
    // You can add directories from plugins and so on.
    // The sky is the limit.

    return $dirs;
});

$data = [
    'title' => 'Ciao Mondo',
];

// some-template-part.php
use ItalyStrap\View;
get_template_part( ['some','template'], 'part', $data );
//or
//...
//$view->render( ['some','template','part'], $data );


// inside some-template-part.php
echo $this->title;

//or

echo $this->get( 'title', 'Some default title' );