fatfree-core
fatfree-core copied to clipboard
Alias and relative path problem
My f3 app is in a subdirectory of the server's document root. Therefore, I am using a <base ...> directive for relative URLs. Now I tried to use the alias filter to generate relative URLs from named routes:
<a href="{{ 'some_route' | alias }}">{{ @some_text }}</a>
The route looks somewhat like this:
$f3->route('GET @some_route: /some_path', 'Page\Start->display');
However, as the routes are prepended with a slash, the resulting URL is /some_path
, which is an absolute path. Right now, I am using a custom filter to simply delete the leading slash, but maybe something built-in would come in handy?
Just as a little side note, the syntax for chaining filters seemed unintuitive to me. I tried the obvious | alias | my_filter
. Any reason filters are separated by commas?
Known problem here too 🖐
I also use a custom alias
filter that overwrites the default behaviour to get around this.
I'm not sure if we can safely change this.. I use a <base>
tag in most of my projects but for those who include the sub-dir in every link it'll break of course. 🤔
I don't use the <base>
tag (mostly because of the hash anchors breaking), which means I have to prefix every link with BASE
, but a handy filter does it for me:
<a href="{{ some_route | url }}">{{ @some_text }}</a>
Maybe we could tweak the default alias
filter, since it doesn't fit either devs (those who use <base>
and those who don't)? If it did automatically prefix the alias with BASE
, it would work in every situation. We could rename it to path
or uri
to avoid confusion with the alias()
function and also to maintain BC.
@chaosflaws you wrote:
Just as a little side note, the syntax for chaining filters seemed unintuitive to me
There's a long-running issue on this topic.
@xfra35
Maybe we could tweak the default alias filter, since it doesn't fit either devs (those who use
and those who don't)? If it did automatically prefix the alias with BASE, it would work in every situation.
I think this is a sensible solution.