1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-12-17 21:22:15 -05:00

Use url() to generate routes in templates

This commit is contained in:
Vincent Jousse 2014-01-08 11:17:46 +01:00
parent 973a2dfb52
commit dddb6809eb
3 changed files with 7 additions and 4 deletions

View File

@ -4,7 +4,6 @@ use Poche\Api\EntryApi;
use Poche\Api\ContentFullTextRssApi;
use Poche\Repository\EntryRepository;
use Silex\Provider\FormServiceProvider;
use Symfony\Component\Translation\Loader\PoFileLoader;
$app = new Silex\Application();
@ -13,6 +12,9 @@ $app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
));
//Generate url in templates
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->before(function () use ($app) {
$app['twig']->addGlobal('layout', $app['twig']->loadTemplate('layout.twig'));
});
@ -30,7 +32,7 @@ $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
),
));
$app->register(new FormServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale_fallbacks' => array('en'),

View File

@ -16,7 +16,8 @@ $front->get('/view/{id}', function (Request $request, $id) use ($app) {
$entry = $app['entry_api']->getEntryById($id);
return $app['twig']->render('view.twig', array('entry' => $entry));
});
})
->bind('view_entry');
$front->match('/add', function (Request $request) use ($app) {
$data = array('url');

View File

@ -9,7 +9,7 @@
{{ 'msg.results'|transchoice(count) }}
{% for entry in entries %}
<div>
<a href="index.php/view/{{entry.id}}">{{ entry.title }}</a>
<a href="{{ path('view_entry', {'id': entry.id}) }}">{{ entry.title }}</a>
<p>{{ entry.content|striptags|slice(0, 300) }}...</p>