PHP code example of francerz / webapp-render-utils

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

    

francerz / webapp-render-utils example snippets


$renderer->renderView('/home/index', [
    'title' => 'Hello World!',
    'paragraph' => 'Hello everyone.'
]);

<html>
    <head>
        <title><?=$title

<head>
    <title><?=$title

<html>
    <?=$view->

<html>
    <head>
        <title><?=$title

<?=$layout = $view->loadLayout('/layouts/main')

class Renderer
{
    public function __construct(
        ResponseFactoryInterface $responseFactory,
        ?StreamFactoryInterface $streamFactory = null
    );

    public function renderRedirect(
        $location,
        int $code = StatusCodeInterface::STATUS_FOUND,
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function render(
        $content,
        $contentType = 'text/plain',
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function renderJson(
        $data,
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function renderCsv(
        array $data,
        $filename = 'file.csv',
        ?CsvOptions $options = null,
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function renderFile(
        string $filepath,
        ?string $filename = null,
        bool $attachment = false,
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function renderCurlResponse(
        CurlHandle $curl,
        string $responseBody,
        ?ResponseInterface $response = null
    ): ResponseInterface;

    public function setViewsBasePath(?string $basepath);

    public function renderView(
        string $viewpath,
        array $data = [],
        ?ResponseInterface $response = null
    ): ResponseInterface;
}

class View
{
    /**
     * Renders a header directly into the view.
     * 
     * @param string $header Defines the header name or name and content.
     * @param string|string[] $content Defines the content of given header.
     */
    public function header(string $header, string|string[] $content = []);

    /**
     * Embeds another view inside the current view.
     * 
     * All `$view` variables are passed automatically into param string $path Path to layout view.
     * @param mixed[] $vars Additional vars to send to layout.
     * 
     * @return Layout
     */
    public function loadLayout(string $path, array $vars = []);
}

class Layout
{
    /**
     * This method starts a section block.
     */
    public function startSection(string $sectionName);

    /**
     * This method ends a section block.
     * 
     * This methods ends section by the last started.
     */
    public function endSection();
}

class LayoutView
{
    /**
     * Embeds section into the layout.
     */
    public function section(string $sectionName);
}