Melody Documentation
  • Why Melody?
  • Quickstart
    • What is Melody?
    • Tutorial
    • Installation
  • Templates
    • Twig
    • Mounting Components
    • Keys and Loops
    • Attributes
    • CSS Classes
    • Inline Styles
    • Refs
    • CSS Modules
  • Melody-Streams
    • Basic concept
    • A Step-by-Step Walkthrough
  • MELODY-STREAMS API
    • createComponent
    • The component function
  • melody-hooks
    • Overview
    • Rules of Hooks
    • Event Handling
    • Separation of Concerns
  • melody-hooks API
    • useState
    • useAtom
    • useEffect
    • useRef
    • useCallback
    • useMemo
    • useReducer
    • usePrevious
  • melody-component
    • Overview
  • melody-hoc
    • Overview
Powered by GitBook
On this page
  • About Twig
  • At a glance
  • Using variables
  • Using blocks
  • Learn more

Was this helpful?

  1. Templates

Twig

PreviousInstallationNextMounting Components

Last updated 6 years ago

Was this helpful?

is how the story of Melody began. We initially started by writing a parser and compiler for Twig. The last step in the process of creating Melody was deciding on what output it should produce and how its component API should look like.

About Twig

Twig is a famous templating language for PHP. It was initially introduced as the default templating language in the Symfony PHP framework.

When compared to Handlebars and other popular templating languages, Twig is quite a bit more powerful. It features template inheritance, blocks, embeds, includes, macros, filters and many other things. Additionally, it has been written to support powerful plugins.

At a glance

Using variables

Embedding a variable into a template is similar to other template languages. The {{ and }} are enclosing an expression which can be used to include a value into a template.

<strong>{{ message }}</strong>

Using blocks

A more powerful feature is blocks. Twig supports many different blocks for all intends and purposes.

{% if isActiveUser %}
<strong>{{ user.name }}</strong>
{% else %}
<a href="/login">Log In</a>
{% endif %}

Learn more

The Twig project offers a very good documentation to the template language which we don't want to duplicate here at the moment. Please take a look at their instead.

Melody behaves identical to Twig in almost all cases unless there are technical limitations preventing us from reaching compatibility. If you notice a difference please report it as a .

Twig
documentation
bug