OS : MacOS 10.14.3
PHP version : >= 7.0
Twig version : 2.x
Introduction
Twig is a template engine for the web developers and designers to implement user interface template in PHP by built-in tags, filters, and functions. The benefit of using Twig to implement user interface template is enhancing the readability of code, reducing the complexity of code, and making it be extendable because the templates can be inherited and included in other templates in Twig. It sounds great, right? So, let's have a try with Twig right now.
IDE
According to the document from Twig, it shows that there are plenty of editors which are able to be used to implement Twig template. In this case, I chose Visual Studio Code as my IDE due to that I can have lots of extensions which helps me backup settings, highlight syntax and provide auto-completion for Twig template. The best thing is it's fast than Netbeans and Eclipse I used to implement projects in PHP and Java. Also, TwigFiddle is a very good online Twig template editor which provides varieties of Twig in different version and the template can be saved online. Furthermore, the testing data can be filled to test the Twig template in real-time. Or you can find other IDE and extensions by click here.
To install Twig Packs for VSC, please refer to the following photo:
Installation
In order to run a Twig template on the local machine, the Twig template engine has to be installed via Composer. The command for Twig template engine installation is as follows:
```sh composer require "twig/twig:^2.0" ```
That's it. It's simple, right?
Trouble Shooting
Q: Where I can find my default PHP?
A: Execute which php
Q: What can I do if 'php -version' still shows php v5.x?
A:
Normally, the default PHP is allocated at `/usr/bin` on macOS. So, just edit your `~/.bash_profile` and insert `export PATH=/usr/bin:$PATH` in this file. After that, just execute `. ~/.bash_profile` to update settings.
Q: What can I do if I got Permission Denied when using composer to install Twig? A: By default, composer is installed in /vendor. So, just run the command as follows:
sudo chown -R $USER /vendor
Reference
Twig Install Twig by composer
I recommend to try Codelobster IDE for Twig development
ReplyDeleteThanks for the recommendation. :)
Delete