- Added a new {% block ... %} token
- Added a new {% php ... %} token
- Fixed a bug with an OR if foreach is empty
This commit is contained in:
1 parent
0e201b77f2
commit
404d1f4359
9 files changed
+143
-22
No files matched your search
@@ -12,7 +12,7 @@ class UrlExtension implements Extension {
|
||||
|
||||
protected array $routes;
|
||||
|
||||
public array $tokens = [ "url" , "route", "asset" ];
|
||||
public array $tokens = [ "url" , "route", "asset", "url.parameters" ];
|
||||
|
||||
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
|
||||
$this->urlBase = trim($urlBase, "/");
|
||||
@@ -31,6 +31,9 @@ class UrlExtension implements Extension {
|
||||
|
||||
case "url":
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->buildUrl($arguments) ?>";
|
||||
|
||||
case "url.parameters":
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->setUrlParameters($arguments) ?>";
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -43,11 +46,16 @@ class UrlExtension implements Extension {
|
||||
$context->pushFunction("route", [ $this, 'buildRouteUrl' ]);
|
||||
}
|
||||
|
||||
public function buildUrl(string $uri = "", array $parameters = []) : string
|
||||
public function setUrlParameters(string $url = "", array $parameters = []) : string
|
||||
{
|
||||
return $this->url() . "/" . ltrim($uri, "/") . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
||||
return $url . ( $parameters ? "?" . http_build_query($parameters) : "" );
|
||||
}
|
||||
|
||||
public function buildUrl(string $uri = "", array $parameters = []) : string
|
||||
{
|
||||
return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $parameters);
|
||||
}
|
||||
|
||||
public function buildAssetUrl(string $uri, array $parameters = []) : string
|
||||
{
|
||||
return $this->buildUrl($uri, array_replace([ 'v' => $this->assetToken ], $parameters));
|
||||
|
||||
Reference in new issue
Block a user