diff --git a/flextype/config/settings.yaml b/flextype/config/settings.yaml index bfdbca01..c52fa681 100644 --- a/flextype/config/settings.yaml +++ b/flextype/config/settings.yaml @@ -23,6 +23,11 @@ theme: default # Available locales to use: flextype/config/locales.yaml locale: en_US +# Application URL +# +# Define custom application url +url: '' + # Valid date format # # - date_format: Valid date format @@ -187,7 +192,7 @@ twig: cache: true debug: false charset: "UTF-8" - extensions: ['Cache', 'Entries', 'Emitter', 'Flash', 'I18n', 'Json', 'Yaml', 'Parser', 'Markdown', 'Filesystem', 'Date', 'Assets', 'Csrf', 'Shortcodes', 'Snippets', 'GlobalVars'] + extensions: ['Cache', 'Entries', 'Emitter', 'Flash', 'I18n', 'Json', 'Yaml', 'Parser', 'Markdown', 'Filesystem', 'Date', 'Assets', 'Csrf', 'Shortcodes', 'Snippets', 'GlobalVars', 'Url'] # Slugify # @@ -230,7 +235,7 @@ image: # # - extensions: Flextype Shortcodes Extension to load. shortcodes: - extensions: ['BaseUrl', 'Entries', 'Registry', 'Snippets'] + extensions: ['BaseUrl', 'Entries', 'Registry', 'Snippets', 'Url'] # API's api: diff --git a/flextype/shortcodes/UrlShortcodeExtension.php b/flextype/shortcodes/UrlShortcodeExtension.php new file mode 100644 index 00000000..91e5a3dd --- /dev/null +++ b/flextype/shortcodes/UrlShortcodeExtension.php @@ -0,0 +1,22 @@ +addHandler('url', static function () use ($flextype) { + if ($this->flextype['registry']->has('flextype.url') && $this->flextype['registry']->get('flextype.url') != '') { + return $this->flextype['registry']->get('flextype.url'); + } else { + return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); + } +}); diff --git a/site/plugins/site/twig/SiteUrlTwigExtension.php b/flextype/twig/UrlTwigExtension.php similarity index 52% rename from site/plugins/site/twig/SiteUrlTwigExtension.php rename to flextype/twig/UrlTwigExtension.php index d7b4c888..ed40ccdd 100644 --- a/site/plugins/site/twig/SiteUrlTwigExtension.php +++ b/flextype/twig/UrlTwigExtension.php @@ -11,8 +11,10 @@ namespace Flextype; use Twig_Extension; use Twig_SimpleFunction; +use Slim\Http\Environment; +use Slim\Http\Uri; -class SiteUrlTwigExtension extends Twig_Extension +class UrlTwigExtension extends Twig_Extension { /** * Flextype Dependency Container @@ -35,15 +37,19 @@ class SiteUrlTwigExtension extends Twig_Extension public function getFunctions() : array { return [ - new Twig_SimpleFunction('site_url', [$this, 'site_url'], ['is_safe' => ['html']]) + new Twig_SimpleFunction('url', [$this, 'url'], ['is_safe' => ['html']]) ]; } /** - * Get Site URL + * Get App URL */ - public function site_url() : string + public function url() : string { - return $this->flextype->SiteController->getSiteUrl(); + if ($this->flextype['registry']->has('flextype.url') && $this->flextype['registry']->get('flextype.url') != '') { + return $this->flextype['registry']->get('flextype.url'); + } else { + return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); + } } } diff --git a/site/plugins/admin/templates/content/entries/media.html b/site/plugins/admin/templates/content/entries/media.html index 58638ad0..1a7ec68b 100644 --- a/site/plugins/admin/templates/content/entries/media.html +++ b/site/plugins/admin/templates/content/entries/media.html @@ -41,17 +41,17 @@ {% set index = loop.index0 %}