PHP code example of mervick / yii2-mthaml
1. Go to this page and download the library: Download mervick/yii2-mthaml 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/ */
mervick / yii2-mthaml example snippets
return [
//....
'components' => [
'view' => [
'renderers' => [
'haml' => [
'class' => 'mervick\mthaml\HamlViewRenderer',
],
'twig' => [
'class' => 'mervick\mthaml\TwigViewRenderer',
],
],
],
],
];
class SiteController extends Controller
{
//....
public function actionIndex()
{
return $this->render('index.haml', $params);
// or if your want to use twig
// return $this->render('index.twig', $params);
}
//....
}
//....
'renderers' => [
'haml' => [
'class' => 'mervick\mthaml\HamlViewRenderer',
'cachePath' => '@runtime/Haml/cache',
'debug' => false,
'options' => [
'format' => 'html5',
// MtHaml escapes everything by default
'enable_escaper' => true,
'escape_html' => true,
'escape_attrs' => true,
'cdata' => true,
'autoclose' => array('meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base'),
'charset' => 'UTF-8',
'enable_dynamic_attrs' => true,
],
],
'twig' => [
'class' => 'mervick\mthaml\TwigViewRenderer',
'cachePath' => '@runtime/Twig/cache',
'debug' => false,
'options' => [
// Same as for haml, except "enable_escaper"
// Twig extension already supports auto escaping, so it turned off for MtHaml
'enable_escaper' => false,
],
],
//....
//....
'renderers' => [
'haml' => [
'class' => 'mervick\mthaml\HamlViewRenderer',
'cachePath' => '@runtime/Haml/cache',
'options' => [
//....
],
'filters' => [
// shorten
'coffee' => 'CoffeeScript',
// also you can specify filter options
'coffee' => [
'filter' => 'CoffeeScript',
'options' => [
'header' => false,
'trace' => '@runtime/Haml/coffee-trace.log',
],
],
],
],
//....
'coffee' => [
// Package: "coffeescript/coffeescript"
'filter' => 'CoffeeScript',
'options' => [
// add a "Generated by..." header
'header' => true,
// reference to token stream (debugging)
'tokens' => null,
// file to write parser trace to (debugging)
'trace' => null,
],
],
'less' => [
// Package: "oyejorge/less.php"
'filter' => 'OyejorgeLess',
'options' => [
// whether to compress
'compress' => false,
// whether units need to evaluate correctly
'strictUnits' => false,
// whether math has to be within parenthesis
'strictMath' => false,
// option - whether to adjust URL's to be relative
'relativeUrls' => true,
// whether to add args into url tokens
'urlArgs' => [],
'numPrecision' => 8,
// import dirs
'importDirs' => [],
// cache dir
'cacheDir' => null
],
],
'less' => [
// Package: "leafo/lessphp"
'filter' => 'LeafoLess',
'options' => [
// import dirs
'importDirs' => [],
],
],
'scss' => [
// Package: "leafo/scssphp"
'filter' => 'Scss',
'options' => [
// import dirs
'importDirs' => [],
// enable Compass integration, depends on "leafo/scssphp-compass"
'enableCompass' => false,
],
],
'markdown' => [
// Package: "michelf/php-markdown"
'filter' => 'MichelfMarkdown',
'options' => [
'forceOptimization' => false,
'empty_element_suffix' => " />",
'tab_width' => 4,
'no_markup' => false,
'no_entities' => false,
'predef_urls' => [],
'predef_titles' => [],
],
],
'markdown' => [
// Package: "michelf/php-markdown"
'filter' => 'MichelfMarkdownExtra',
'options' => [
// Same as for MichelfMarkdown
],
],
'markdown' => [
// Package: "cebe/markdown"
'filter' => 'CebeMarkdown',
'options' => [
'forceOptimization' => false,
'html5' => false,
],
],
'markdown' => [
// Package: "cebe/markdown"
'filter' => 'CebeMarkdownExtra',
'options' => [
'forceOptimization' => false,
'html5' => false,
],
],
'markdown' => [
// Package: "cebe/markdown"
'filter' => 'CebeGithubMarkdown',
'options' => [
'forceOptimization' => false,
'html5' => false,
'enableNewlines' => false,
],
],
'markdown' => [
// Package: "kzykhys/ciconia"
'filter' => 'CiconiaMarkdown',
'options' => [
'forceOptimization' => false,
'tabWidth' => 4,
'nestedTagLevel' => 3,
'strict' => false,
],
],
'markdown' => [
// Package: "league/commonmark"
'filter' => 'CommonMark',
'options' => [
'forceOptimization' => false,
],
],
'markdown' => [
// Package: "fluxbb/commonmark"
'filter' => 'FluxBBMarkdown',
'options' => [
'forceOptimization' => false,
],
],
'markdown' => [
// Package: "erusev/parsedown"
'filter' => 'Parsedown',
'options' => [
'forceOptimization' => false,
],
],
'rest' => [
// Package: "gregwar/rst"
'filter' => 'ReST',
// no options
],
//....
'renderers' => [
'twig' => [
'class' => 'mervick\mthaml\TwigViewRenderer',
'options' => [
//...
],
'extensions' => [
'Text', # Provides useful filters for text manipulation;
'I18n', # Adds internationalization support via the gettext library;
'Intl', # Adds a filter for localization of DateTime objects;
'Array', # Provides useful filters for array manipulation;
'Date', # Adds a filter for rendering the difference between dates.
],
],
//....