twig 5 star rating partial

Simple snippet/partial for a twig star rating with fontawesome <div> {% if bewertung %} {% for i in range(1,5) %} {% if bewertung >= max(0, i-0.25) %} <span class=”fa fa-star”></span> {% elseif (bewertung > (i-0.75)) %} <span class=”fa fa-star-half-o”></span> {% else %} <span class=”fa fa-star-o”></span> {% endif %} {% endfor Read more…

active language check

{% if activeLocale == ‘de’ %} {% component ‘staticMenuDE’ class=”nav navbar-nav navbar-right” %} {% else %} {% component ‘staticMenuEN’ class=”nav navbar-nav navbar-right” %} {% endif %} https://octobercms.com/plugin/rainlab-translate

some Twig functions / helper

Template function to generate assetĀ URLs Usage like this: <link rel=”stylesheet” href=”{{ assets(‘styles.css’) }}”> AndĀ here is the Twig function: $app[‘twig’]->addFunction(new \Twig_SimpleFunction(‘assets’, function ($uri = ”) use ($app) { return ‘//’ . $app[‘request’]->getHttpHost() . $app[‘request’]->getBasePath() . ‘/assets/’ . trim($uri, ‘\/’); })); Template function for reading session value with dot annotation Access session Read more…

Twig asset helper

This function generates an URL for project assets. $app[‘twig’]->addFunction(new \Twig_SimpleFunction(‘asset’, function ($uri = ”) use ($app) { return ‘//’ . $app[‘request’]->getHttpHost() . $app[‘request’]->getBasePath() . ‘/PATH_TO_ASSETS/’ . trim($uri, ‘/\’); })); Usage: {{ asset(‘css/styles.css’) }} {{ asset(‘js/main.js’) }} Here are other solutions: http://silex.sensiolabs.org/doc/cookbook/assets.html