From fe228dd8feffb1c0670fd7cd87c1df97b8b7f362 Mon Sep 17 00:00:00 2001 From: Max Izmailov Date: Tue, 24 Apr 2012 13:03:03 +0200 Subject: [PATCH] Twig filter to get absolute path of files in /content folder. Usage: {{ image.url | absolute }} --- extensions/twig-extensions.inc.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extensions/twig-extensions.inc.php b/extensions/twig-extensions.inc.php index 0a8a1c5d..0d888df2 100644 --- a/extensions/twig-extensions.inc.php +++ b/extensions/twig-extensions.inc.php @@ -16,6 +16,7 @@ public function getName() { public function getFilters() { # custom twig filters return array( + 'absolute' => new Twig_Filter_Method($this, 'absolute'), 'context' => new Twig_Filter_Method($this, 'context') ); } @@ -130,6 +131,14 @@ function sortby($object, $value) { uasort($sorted, array($this, 'custom_str_sort')); return $sorted; } + + # + # transforms relative path to absolute + # + function absolute($relative_path) { + # assume that all content lies in http://something.com/content/ + return (($_SERVER['HTTPS'] ? 'https://' : 'http://')).$_SERVER['HTTP_HOST'].strstr($relative_path, '/content'); + } }