About twigfiddle.com

Twig is a modern template engine for PHP, based on Django and Jinja syntaxes. It is an opensource product, released under the 3-Clause BSD License by Fabien Potencier.

As Twig becomes well known, a lot of questions are asked on Q/A websites, such as http://stackoverflow.com, and some answers can be more explicit with runnable examples.

A lot of websites exists to run code online: jsfiddle.net for Javascript, sqlfiddle.com for database queries, codepad.org for C, C++, PHP, (and lots of others)... twigfiddle.com's aim is to provide a small development environment to develop, run, store and access Twig code online.

 
Table of contents
 
What am I supposed to do here?
 

If you do not know Twig or basic templating language concepts, this site is not going to be very useful to you. However, if you are a twig/Symfony2 developer, there are a few different use-cases of twigfiddle intended for you:

  • You want help with a tricky template, and you'd like to post a question to a Q/A site like StackOverflow. Create a representative view (templates and context) and post a link to it in your question. Unique URLs for each fiddle will be generated as you use the site (even if you can create your custom urls), just copy and pate the URL that you want to share, and it will be available for anyone who wants to take a look. They will be able to use your template as a starting point for answering your question. When they have something they'd like to share with you, they can then send you a link back to their template.

  • You want to compare and contrast Twig features in different versions. twigfiddle easily lets you switch which version your template and your context run against. This will allow you to quickly evaluate template porting efforts, or test a template in the version that match with your working environment.

  • You do not have a particular development platform readily available, but you would like to see what a given template would look like in that environment. Using twigfiddle, you don't need to bother spinning up a whole installation for your evaluation; just create your template and run it here!

  • You want to know what is the compiled result of a twig template. As twig files are compiled into php classes, this is really interesting to see the resulting PHP file to understand twig internals, especially if you're dealing with advanced extensions.
 
Top
How to create a fiddle?
 

To create a fiddle, just go to twigfiddle.com to get to the fiddle's editor.

You can customize your fiddle's URL by going to http://twigfiddle.com/whatever-you-want.

  • Choose the right Twig version you're using with your project

  • Code your template

  • Select your context format between YAML, XML, JSON or INI

  • Write the context you need to use with your template(s)

  • if you need to use several templates (to use extends, macro, include... tags), click on "Add template".

    • Select the template that should be run first (the one which extends or include the others)

    • You can delete useless templates by clicking on the small trash

    • You can have 10 templates per fiddle

  • You can run your fiddle by clicking "Run" button to check your result

  • When you're done, you can save your fiddle and share it

 
Top
How to read fiddle's result?
 
  • The result status appears as a small flag:

    • Green Flag: result were rendered without problems.

    • Red Flag: at least one template contains error(s).

    • Yellow Flag: context's format is invalid.

    • Green Flag: execution ended up in a fatal error.

  • Click on the "Select result" to quickly select your result in order to copy it to your clipboard.

  • Your result appears without extra spaces, click on "Show raw result" if you want to see the real result coming from your fiddle's execution

  • Duration regards only the time it took to run the fiddle, page load time is not counted.

 
  • Click on "Dump context" to see your context as a var-dumped PHP array, this is useful to double-check that it was correctly entered.

  • Click on "Show compiled templates" to look at PHP classes generated from your twig templates. This is really helpful to know how twig works to avoid confusions when building complex templates, or even custom tags.

 
  • On errors, all Twig exceptions and their details come back to you, so you can fix your code quickly.

  • If you think you've found a bug on the project, you can click on the line that handled the exception to get further on github.

 
Top
Other options available when visiting an existing fiddle
 

Other options are available when you're saving or accessing an already-saved fiddle.

  • You can switch between several revisions of a fiddle by using the dropdown menu.

  • If you do not own a fiddle and want to update it, you can click on "Create new revision" button to fork it.

  • If you've just created a fiddle, you can click save button until your session expires. Signed-in users can save their own fiddles all the time.

  • You can set a title to your fiddle, this is useful as, for example, Stackoverflow opens external URLs in the current tab. By giving URLs related to your fiddle, you help people who actually helps you to get back to your question.

  • You can assign up to 5 tags to your fiddles, this is useful if you're building tools with it (such as code generators) and want to filter them quickly in the fiddle's browser. Removed due to bad implementation / browsing slowness.

 
Top
How to use the fiddle's browser
 

By clicking on Browse button, you can access fiddle's browser.

This page let you browse and/or search for fiddles.

  • All fiddles matching your criterias are displayed with the following information:

    • Fiddle's hash and revision

    • Title and tags

    • Creation date, author and visit counter

    • An open button that let you open fiddle in a new tab.

  • You can search fiddles by keywords separated by a space: all fiddles containing at least one keyword will match.

  • You can search fiddles by tags, all fiddles containing all given tags will match.

  • Click on "Create new fiddle"'s button or on Twigfiddle's logo to get back to the fiddle editor.

 
Top
Other options for registered users
 

Registered users can change fiddle's visibility.

  • Set your fiddle's visibility to public to let everybody access your fiddle, even by using the fiddle's browser.

  • Set your fiddle's visibility to unlisted to let only people who knows your fiddle's URL access it; it will be available in the fiddle's browser only to you.

  • Set your fiddle's visibility to private to let nobody access your fiddle's revision. Only you will be able to access it.

 

Registered users can bookmark fiddles they don't own.

  • You are able to filter bookmarked fiddles in the fiddle's browser.

  • You can overwrite title and tags of bookmarked fiddles.

  • If you unbookmark a fiddle, you loose the title and tags you've set to it.

 

About your account

  • You can see in the picture what we store about your account.

  • You are free to remove your account when you want, by following this link. This will automatically remove your private fiddles and all your bookmarks.

 
Top
Special thanks
 
 
Top
License
 
  • Twigfiddle's logo is licensed under the Creative Common Attribution 4.0 International license.

    You are free to:
    
        Share — copy and redistribute the material in any medium or format
        Adapt — remix, transform, and build upon the material for any purpose, even commercially.
    
        The licensor cannot revoke these freedoms as long as you follow the license terms.
    
    Under the following terms:
    
        Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    
        No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
    
    Notices:
    
        You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
        No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
    

  • Twigfiddle's source code is licensed under the MIT license.

    The MIT License (MIT)
    
    Copyright (c) 2015 alain tiemblo <alain // fuz // org>
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
    

 
Top
About the author
 

I am Alain Tiemblo, a lazy and passionate web developer. I spend most of my life sleeping, eating, swimming and, of course, coding. I am living in Nantes (France), a nice and animated city close to the Atlantique ocean. I spend my vacations travelling, with a special attraction to China after being there 9 months already.

I enjoy being that lazy developer as I am always looking for ways to do more with less efforts and time. For me, but also and particularily for the users who will use my work. And I love searching for solutions to develop impossible stuffs, such as multi-threading simulation in PHP, user-friendly parsers, strong enconding matters, captcha-breakers and so on.

I began computer science at 13 years old, as an IRC chatter. I developped my first mIRC script because I seen a game robot that wasn't opensource, and wanted to put it on my own channels. This was the very beginning of an incredible adventure. I spent 8 years on IRC, coding games, moderation and administration robots, proxy to bypass school's firewall to chat during classes, chat client for mobile devices throught http, chat analytics and more.

After being gradulated from secondary school, I studied computer science at the European Institute of Technology, a 5-years course that creates self-learner nerds. During first 2 years, it was forbidden to use existing libraries: if we required a function (whichever one), we needed to code it! A nice way to learn a lot of low-level stuffs, and to understand how things run. The other years covered a large variety of technologies, from langages, system and network administration, to technical topics such as code parsing, network development, computer graphics, artificial intelligence and so on. Coupled with internships and international studies, the many things I learnt made me able to choose THE job I'm made for: web developer.

I am also a Zend Certified Engineer, who done the examination just for fun.

You can find some more of my geeky activity on Stackoverflow:

profile for Ninsuo on Stack Exchange, a network of free, community-driven Q&A sites

Alain Tiemblo

 
Top
Unsuscribe...
reCaptcha