# Danky

Danky

The Chevere/Danky package provides a typed PHP template system.

👏 With this package you can create re-usable, strict, highly-testable templates that work as classes.

💡 Danky introduction

Read Danky, typed templates for PHP (opens new window) at Rodolfo's blog for a compressive introduction to this package.

# Installing

Danky is available through Packagist (opens new window) and the repository source is at GitHub (opens new window).

composer require chevere/danky

# Templates

A Danky template is a class extending Template:

💡 In the code below, the return is an string formatted in Heredoc (opens new window) syntax. You can also use Nowdoc (opens new window), double quoted (opens new window) and single quoted (opens new window) string literals.

<?php // Quote.php

use Chevere\Danky\Template;

class Quote extends Template
{
    public function __construct(string $text, string $author) {
        $this->render =
            <<<HTML
            <quote>"$text" --$author</quote>
            HTML;
    }
};

Templates must assign the $render property, which accepts string and Template types. When needing to render the template is easy as:

<?php
echo
    new Quote(
        text: 'Hello, world!',
        author: 'Rodolfo'
    );

Which echoes:

<quote>"Hello, world!" --Rodolfo</quote>

# Extra Features

Danky doesn't has extra features yet, but we are aware of the needs that usually sprout in the presentational layer. At this time we hope that the built-in PHP library will be enough for most use cases. Don't hesitate to open an issue (opens new window) if you need extra features.

# Escaping

Danky doesn't provide escaping functionality. You can use the built-in String Functions (opens new window) of the standard PHP library.

For example, using htmlspecialchars (opens new window):

$safe  = htmlspecialchars($string, ENT_QUOTES, 'UTF-8')

👉 We encourage you to bring your favorite safe-string package, for example voku/stringy (opens new window) or even your own.

# Filtering & Validation

Danky doesn't provide filtering functionality. You can use the built-in filter_var (opens new window) function which provides a myriad of filters (opens new window) which can be used for filtering and validation.

Last Updated: 10/11/2022, 11:12:32 PM