Use Cockpit and Twig together.
- Download zip and unpack to 'your_cockpit_folder/modules/addons/twig'.
- Make sure you require 'your_cockpit_folder/bootstrap.php'.
- Hook up your Twig_Environment to the module.
cockpit('twig')->use($your_twig_env);
- Start using Cockpit in your templates.
define('DOCROOT', $_SERVER['DOCUMENT_ROOT']);
require_once('vendor/autoload.php'); // If you're using composer.
require_once('cockpit/bootstrap.php');
// Setup Twig templating engine
$loader = new Twig_Loader_Filesystem(DOCROOT . '/templates');
$twig = new Twig_Environment($loader, array(
'cache' => DOCROOT . '/cache',
));
cockpit('twig')->use($twig);
$template = $twig->loadTemplate('index.twig'); // Make sure '/templates/index.twig' exists.
echo $template->render();
Retrieve all items for a collection:
{% for item in collection('projects') %}
{{ item.name }}
{% endfor %}
Query a collection:
{% for item in collection('projects', {active: 1}) %}
{{ item.name }}
{% endfor %}
Render the entire region, with template:
{{ region('info') }}
Render one field:
{{ region_field('info', 'title') }}
Parameters are: region name & field name.
Print an image tag for each image in gallery:
{% for image in gallery('projects') %}
{{ thumbnail(image.path) }}
{% endfor %}
or just the url:
{% for image in gallery('projects') %}
<img src="{{ thumbnail_url(image.path) }}" />
{% endfor %}
{{ form('contact') }}
<input type="text" name="form[name]" />
<input type="email" name="form[email]" />
<input type="submit" value="submit" />
</form>
get_user() returns a User object representing the currently logged in user if any. has_access($resource, $action) returns true or false depending on the granted permissions for that action and resource and for the currently logged in user.
{% set user = get_user() %}
{% if user %}
Nice to see you again {{ user.name }}!
{% if has_access('gallery', 'create') %}
Let's snap some pictures.
{% endif %}
{% endif %}
Copyright 2014 maneuver under the MIT license.