Download the PHP package noadek/twiggy without Composer

On this page you can find all versions of the php package noadek/twiggy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twiggy

Allows you to use Twig without replacing the default blade templating engine in Laravel 5. Based on Edmundas Kondrašovas Twiggy for CodeIgniter

Requirements

Twiggy requires Laravel 5.

Installation

Require this package with Composer

Quick Start

Once Composer has installed or updated your packages you need to register Twiggy with Laravel itself. Open up config/app.php and find the providers key, towards the end of the file, and add the Twiggy Service Provider, to the end:

Now we will use Artisan to add the new twig config file:

Configuration

The php artisan vendor:publish --provider="Twiggy\Provider\TwiggyServiceProvider" provides you with a default twiggy.php configuration file located in config directory.

Set up dir structure

Twiggy follows a specific theme-layout-template structure that helps separates your logic from your views. You can create multiple themes and layouts and switch themes and layout on the fly! By default Twiggy will look for your twig files in a themes folder at the server root (you can change this if you like in the config/twiggy.php file provided). So you should create these directories and files.

  1. Create a directory structure:

  2. Create a default layout index.twig and place it in layouts folder:

  3. Create a default template file index.twig at the root of default theme folder:

  4. You should end up with a structure like this:

Usage

At this point you can now begin using twig. Twiggy basically provides you with various helpers for setting up your views or templates.

You call the twig template like a view but with the twig() helper.

Twiggy provides other useful helpers for building a theme-layout-template structure for your views.

Setting the theme

The default twiggy theme is 'default'. This can be changed in the config/twiggy.php file. To create a new theme, add a new folder with the desired theme name in the themes folder.

Setting your theme on the fly.

'default' can be changed to any other theme you may have created. You may want to build a CMS-like system, this can be manipulated to be set from a database, so users of the system can change themes.

Setting a layout

Different pages may have different layouts depending on the structure and design of your app. Twiggy lets you set and switch layouts as you like. See the example below:

In the example, the index page will use the 'default' theme and the 'index' layout to display the 'index' template. The test page, on the other hand, will use the 'default' theme but the 'blog' layout to display the 'post' template.

Setting the page title

Twiggy provides three functions for building page titles. This functions can be used depending on your SEO technique. The 'setPageTitle' function sets the title of the page, 'appendPageTitle' adds a specified string after the set title while 'prependPageTitle' adds the specified string before the set title.

Both the 'appendPageTitle' and 'prependPageTitle' will use the specified 'title_separator' in the config/twiggy.php file to separate titles.

Let's add a page title to our previous example.

For this to work, replace the <title>Default layout</title> in the index.twig layout file with <title>{{ title }}</title>

Here the index page will display the title 'Pages | About Me'. This can also be achieved using

Setting page metas

Twiggy provides a 'setPageMeta' function for setting dynamic meta tags. This can be useful for setting Open Graph markup for Facebook, Twitter, etc. It can also be used for setting Google site verification meta and other dynamic meta tags.

Let's update our example with meta tags

Also for this to work we have to add the {{ meta }} variable to the layout

Registering functions and filters

Twig is sandboxed. You can’t just use any PHP function by default, you can’t access things outside the given context and you can’t use plain PHP in your templates. This is done by design, it forces you to separate your business logic from your templates.

You can however specify a list of PHP functions/filters allowed within your templates by adding required functions and filters to the 'register_functions' and 'register_filter' array respectively in the config/twiggy.php file as shown:

This tells Twiggy to register the functions 'date', 'phpversion' and a custom function called 'foo'.

Creating custom functions

Custom functions or filters can be created in several ways in Laravel. You can always find cleaner ways to do it but here's one way to do it using a ServiceProvider:

Create the helpers file that will contain your custom functions and filters.

And finally add the service provider to the config/app.php file.


All versions of twiggy with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
twig/twig Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package noadek/twiggy contains the following files

Loading the files please wait ....