Skip to content

Instantly share code, notes, and snippets.

@dreadfullyposh
Last active December 12, 2016 09:31
Show Gist options
  • Save dreadfullyposh/c08c1730607ce5829759 to your computer and use it in GitHub Desktop.
Save dreadfullyposh/c08c1730607ce5829759 to your computer and use it in GitHub Desktop.
{
"name": "confluxgroup/twigee",
"description": "Twig + EE",
"authors": [
{
"name": "Jeremy Gimbel",
"email": "[email protected]"
}
],
"require": {
"rsanchez/deep": "1.*",
"twig/twig": "1.*",
"slim/slim": "2.*"
}
}
<?php
// Slim, Twig and Deep were all added through Composer. So this is just the index.php that loads up Slim and kicks it off.
// This is really just a very rigid example of how it could work. Obviously would need to be a lot more dynamic to be useful.
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'twigee',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => 'exp_'
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
use rsanchez\Deep\App\Entries;
require_once 'vendor/twig/twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
$app = new \Slim\Slim();
$app->get('/', function () {
$loader = new Twig_Loader_Filesystem('./templates');
$twig = new Twig_Environment($loader, array(
//'cache' => './cache',
'debug' => true
));
$entries = Entries::channel('blog')
->limit(10)
->get();
echo $twig->render('test.html', array('entries' => $entries));
});
$app->run();
{% for entry in entries %}
<h4>{{ entry.title }}</h4>
{{ entry.blog_body }}
<h5><em>Related Posts</em></h5>
<ul>
{% for related in entry.blog_related_entries %}
<li>{{ related.title }}</li>
{% endfor %}
</ul>
<hr>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment