PHP code example of midorikocak / view

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

    

midorikocak / view example snippets


$articleData = [
    'title' => 'Writing object oriented software is an art.',
    'sections' => [
        [
            'title' => 'Introduction',
            'content' => [
                'Some people say that you have to be genius, or man,
        but they mostly does not undertsand what is humble programming.
        Programming should be a modest person\'s craft.',
                'Generally those people does exclude others, create clickbait articles,
            they make you feel less confident.',
                'Do not care about them and just try to create things. Learn. Be hungry.',
            ],
        ],
    ],
    'created' => '2020-01-25 00:00:00',
];

// template.php

if (isset($created) && $created !== '') {
    $datetime = strtotime($created);
    $formattedDate = date('D, j Y', $datetime);
}

$renderer = new FileRenderer();
$view = new View($this->renderer);
$view->setTemplate('template.php');
echo $this->view->render($this->articleData);

$templateRenderer = new TemplateRenderer();
$view = new View($templateRenderer);
$view->setTemplate('tests/View/plain.template.html');
$this->assertNotEmpty($view->render(
    [
        'title' => 'Object Oriented Programming',
        'sectionTitle' => 'Introduction',
        'parapgraph' => 'Writing object oriented software is an art.',
        'created' => '2020-01-25 00:00:00',
        'formatted' => 'Mon 25, 2020',
    ]
));

$bladeRenderer = new BladeRenderer('tests/View', '/tmp');
$view = new View($bladeRenderer);
$view->setTemplate('app');
echo $view->render(
    [
        'title' => 'OOP',
        'content' => 'Writing object oriented software is an art.',
    ]
);



declare(strict_types=1);

namespace midorikocak\view;

interface RendererInterface
{
    public function render(string $template, array $data): string;
}

$article->template = 'tests/View/posts/post.php';
echo $article->render();

$templateRenderer = new TemplateRenderer();
$view = new View($templateRenderer);

$article->view = $view;
$article->template = 'tests/View/plain.template.html';

echo $article->render();