Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions modules/system/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use System\Classes\MediaLibrary;
use System\Classes\MarkupManager;
use Twig\TwigFilter as TwigSimpleFilter;
use Twig\TwigFunction as TwigSimpleFunction;
use Twig\Extension\AbstractExtension as TwigExtension;

/**
Expand Down Expand Up @@ -35,7 +36,14 @@ public function __construct()
*/
public function getFunctions()
{
$functions = [];
$functions = [
new TwigSimpleFunction('app', [$this, 'appFilter']),
new TwigSimpleFunction('media', [$this, 'mediaFilter']),
new TwigSimpleFunction('asset', [$this, 'assetFilter']),
new TwigSimpleFunction('resize', [$this, 'resizeFilter']),
new TwigSimpleFunction('imageWidth', [$this, 'imageWidthFilter']),
new TwigSimpleFunction('imageHeight', [$this, 'imageHeightFilter']),
];

/*
* Include extensions provided by plugins
Expand All @@ -53,11 +61,12 @@ public function getFunctions()
public function getFilters()
{
$filters = [
new TwigSimpleFilter('app', [$this, 'appFilter'], ['is_safe' => ['html']]),
new TwigSimpleFilter('media', [$this, 'mediaFilter'], ['is_safe' => ['html']]),
new TwigSimpleFilter('resize', [$this, 'resizeFilter'], ['is_safe' => ['html']]),
new TwigSimpleFilter('imageWidth', [$this, 'imageWidthFilter'], ['is_safe' => ['html']]),
new TwigSimpleFilter('imageHeight', [$this, 'imageHeightFilter'], ['is_safe' => ['html']]),
new TwigSimpleFilter('app', [$this, 'appFilter']),
new TwigSimpleFilter('media', [$this, 'mediaFilter']),
new TwigSimpleFilter('asset', [$this, 'assetFilter']),
new TwigSimpleFilter('resize', [$this, 'resizeFilter']),
new TwigSimpleFilter('imageWidth', [$this, 'imageWidthFilter']),
new TwigSimpleFilter('imageHeight', [$this, 'imageHeightFilter']),
];

/*
Expand Down Expand Up @@ -105,6 +114,16 @@ public function mediaFilter($file)
return MediaLibrary::url($file);
}

/**
* Converts supplied file to a URL relative to the `app.asset_url` config.
* @param string $file Specifies the asset-relative file
* @return string
*/
public function assetFilter($file)
{
return Url::asset($file);
}

/**
* Converts supplied input into a URL that will return the desired resized image
*
Expand Down