PHP code example of larsgmortensen / liteview

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

    

larsgmortensen / liteview example snippets


use LiteView\LiteView;

use LiteView\LiteView;

LiteView::render(
    'home.html',                  // Template file (relative to $templatePath)
    '/path/to/templates/',        // Template directory
    true,                         // Enable cache
    '/path/to/cache/',            // Cache directory
    true,                         // Trim whitespace
    true,                         // Remove HTML comments
    ['title' => 'Hello World'],   // Data/template variables
    true                          // Allow raw PHP blocks ({? ... ?})
);

$html = LiteView::renderToString(
    'page.html',
    '/path/to/templates/',
    true,
    '/path/to/cache/',
    false,
    false,
    ['user' => $user],
    false // disallow raw PHP tags
);

LiteView::clearCache();

LiteView::render(
    string $template,
    string $templatePath,
    bool   $cacheEnabled,
    string $cachePath,
    bool   $trimWhitespace = false,
    bool   $removeHtmlComments = false,
    array  $data = [],
    bool   $allowPhpTags = true
): void

LiteView::renderToString(...): string

LiteView::clearCache(): void
html
{% extends "layout.html" %}

{% block title %}Home{% endblock %}

{% block header %}<h1>Welcome</h1>{% endblock %}

{% block content %}
    <p>Welcome to the home page, list of colors:</p>
    {% if (isset($something) || isset($something["else"])) %}
        <div>Do something</div>
    {% endif %}

    <ul>
        {% foreach ($colors as $color) %}
        <li>{{ $color }}</li>
        {% endforeach %}
    </ul>
{% endblock %}
html
<ul>
    {% foreach ($items as $item) %}
        <li>{{ $item }}</li>
    {% endforeach %}
</ul>
html
{? echo strtoupper("hello world"); ?}