Nathan's Brain
  • Introduction
  • Incubator
  • American Sign Language
  • Art
  • Behavior Change
    • Akrasia
      • Beeminder
      • Procrastination
  • Career
  • Civil Discourse
  • Communication
  • Computer Science
    • Artificial Intelligence
  • Creativity
    • Writing
  • Design
    • Color
    • Design Process
    • Stock
    • Web Design
  • Economics
  • Engineering
  • Entrepreneurship
    • Customer Development
    • Marketing
      • Newsletter Publishing
    • Pricing
  • Environment
    • Energy
    • Transportation
  • Failure & Vulnerability
  • Freelancing
    • Estimating
  • Futurism
  • Governance & Politics
    • Representation & Voting
  • Health
  • Humane Tech
    • Phone Usage
  • Infotainment
  • Linguistics
  • Minimalism
  • Personal Finance
    • FIRE Movement
    • Investing
  • Productivity
    • Attention Management
    • Audio for Focus
    • Automation
    • Task Management
    • Time Management
  • Programming Languages
    • JavaScript
      • Snippets
    • PHP
    • Python
      • Development Environments
      • Package Management & Distribution
  • Psychology
  • Quantified Self
    • Experience Sampling Method
  • Rationality
    • Bayes' Theorem
    • Cognitive Biases
  • Religion
    • Adventism
  • Remote Work
  • Research
    • Note Taking
  • Science
  • Self-Study
    • Accessibility & Usability
    • Algorithms
    • Artificial Intelligence
    • Cryptography
    • Data Science
    • Design Patterns
    • Freelancing
    • Functional Programming
    • Game Development
    • Graphic Design
    • Grid Layout
    • Microservices
    • PWAs
    • SaaS
    • Software Craft
    • Software Management
    • Statistics
    • SVG
    • UI Design
    • Web Animation
  • Software Development
    • API Design
    • Collaboration
    • Command Line
    • git
    • Integrated Development Environments
    • Knoxville Scene
    • Paradigms
    • Refactoring
    • Self-Care
    • Testing
  • Technology History
    • People
    • Timeline
  • Web Development
    • Accessibility & Usability
    • APIs
    • Browsers
    • Content Management Systems
    • CSS
    • Email
    • Frameworks
      • React
    • Libraries
    • No Code & Low Code
    • Performance
    • Serverless
    • Static Sites
    • Testing
    • Twig
    • Type
Powered by GitBook
On this page
  • Snippets
  • Links
  1. Web Development

Twig

PreviousTestingNextType

Last updated 5 years ago

Snippets

Prevent returned HTML from being auto-escaped by Twig ():

class MyParser {
    public function getHTML() {
         $rawString = '<a href="#">Hello World</a>'
         return new \Twig\Markup( $rawString, 'UTF-8' );
    }
}

Links

#article - "A hash is one of . It has a key and a value. The pairs are separated by a comma and enclosed in curly braces."

#webapp

#article - “{{ lang.test }} will try to invoke one of the following, in this order:”

  • $lang->test

  • $lang->test()

  • $lang->getTest()

  • $lang->isTest()

  • Search order:

    • check if foo is an array and bar a valid element;

    • if not, and if foo is an object, check that bar is a valid property;

    • if not, and if foo is an object, check that bar is a valid method (even if bar is the constructor - use __construct() instead);

    • if not, and if foo is an object, check that getBar is a valid method;

    • if not, and if foo is an object, check that isBar is a valid method;

    • if not, and if foo is an object, check that hasBar is a valid method;

    • if not, return a null value.

  • foo['bar'] on the other hand only works with PHP arrays:

    • check if foo is an array and bar a valid element;

    • if not, return a null value.

#article - “For convenience's sake foo.bar does the following things on the PHP layer:”

source
Key Value Arrays in Twig
several types of literals available in Twig
Twig Documentation
TwigFiddle
Twig property search order SO answer
Twig property search order Twig docs