eZ Platform Discussions

Urlalias not working

Hi,

Why doesn’t this work when I have custom urlalias defined:

<a href="{{ path( 'ez_urlalias', {'locationId': 123}) }}">Some Link</a>

It always displays the system url.

I solved it through twig extensions (example bellow), but I’m not happy with it. Is there a more elegant solution?

BR

Example:

<a href="{{ ezurl(123) }}">SomeLink</a>

public function ezurl($locationId)
{
    $location = $this->locationService->loadLocation($locationId);

    if($this->urlAliasService->listLocationAliases($location, true)) {
        return $this->urlAliasService->listLocationAliases($location, true)[0]->path;
    }

    return $this->urlAliasService->listLocationAliases($location, false)[0]->path;
}