Skip to content

Instantly share code, notes, and snippets.

@DC-development
Created June 22, 2014 00:52
Show Gist options
  • Save DC-development/a58ee5cbd0354e820fec to your computer and use it in GitHub Desktop.
Save DC-development/a58ee5cbd0354e820fec to your computer and use it in GitHub Desktop.
With fake object
<?php
/* $Id$ */
/**
* @file
* Very simple DRUPAL module
*/
//see all messages for debugging
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//Because we need the twig-lib for the hello world example
//actually you should add this in index.php
require_once './vendor/autoload.php';
/**
* Implementation of hook_help().
*/
function hello_world_help($section) {
switch ($section) {
case 'admin/help#hello_world':
$output = '<p>Hello world help...</p>';
return $output;
case 'admin/modules#description':
return 'Hello world module description...';
}
}
/**
* Implementation of hook_menu().
*/
function hello_world_menu() {
$items['hello'] = array(
'title' => 'Using Twig with Drupal', // page title
'page callback' => 'hello_world_page', // callback function name
'access callback' => TRUE, // every user can look at generated page
'type' => MENU_CALLBACK // define type of menu item as callback
);
return $items;
}
/**
* Implementation of hook_page().
* Using Twig Engine for output.
*/
function hello_world_page() {
$loader = new Twig_Loader_Filesystem('./twig');
$twig = new Twig_Environment($loader, array(
'cache' => './twig/_temp',
'debug' => 'true'
));
//fake object
$td = [
'class'=> 'default',
'image' => 'holder.js/372x134/auto/',
'title' => 'myTitle',
'text' => 'Teaser Text Teaser Text Teaser Text Teaser Text Teaser Text Teaser Text',
'content' => [
'featureList' => [
'one',
'two',
'three',
],
'priceValue' => '54',
'priceUnit' => '€',
'percentage' => '23%'
]
];
$ret = "";
$ret .= $twig->render('test.html.twig', array(
'teaserData' => $td
));
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment