Skip to content

Crecket/custom-twig-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

custom-twig-extension

GitHub release Packagist

Content

  1. Introduction
  2. Requirements
  3. Installation
  4. Usage
  5. License

Introduction

This repo contains my custom twig extension. In here you'll find a few native php functions added to twig as a twig extension. Things like creating a random number or using json_decode can now be done directly in Twig.

Requirements

  • Twig ^1.25

Installation

Composer

  1. Require the repo with composer composer require crecket/custom-twig-extension
  2. Add the extension to the twig view (custom_twig_extension is the class)
$twig = new Twig_Environment();
$twig->addExtension(new custom_twig_extension());

Manual

  1. Download the source
  2. Require the file
  3. Add the extension to the twig view

Usage

Using these functions and filters is the same as the native functions and filters.

Quick example:

  • print_r()
{{ print_r(array) }}
  • json_decode
{{ some_variable|json_decode }}

List

Functions

  1. dumpPre(var1, var2, var3 ...)
  2. md5(password)
  3. password_hash(password)
  4. phpinfo()
  5. print_r(array)
  6. pseudoBytes(length)
  7. randomHex(length)
  8. randomInt(length)
  9. randomString(length)
  10. unsetSession(key)
  11. wordwrap(string, length, limiter = "\n", cut)

Filters

  1. json_decode
  2. urlDecode

Globals

  1. sessionVars //Returns all php SESSION variables in array form