Skip to content

Commit

Permalink
Twig filter to get absolute path of files in /content folder. Usage: …
Browse files Browse the repository at this point in the history
…{{ image.url | absolute }}
  • Loading branch information
kvakes committed Apr 24, 2012
1 parent 3de6607 commit fe228dd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions extensions/twig-extensions.inc.php
Expand Up @@ -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')
);
}
Expand Down Expand Up @@ -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');
}

}

Expand Down

0 comments on commit fe228dd

Please sign in to comment.