Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Twig filter to get absolute path of files in /content folder. Usage: …

…{{ image.url | absolute }}
  • Loading branch information...
commit fe228dd8feffb1c0670fd7cd87c1df97b8b7f362 1 parent 3de6607
@kvakes kvakes authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 extensions/twig-extensions.inc.php
View
9 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');
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.