Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias and relative path problem #322

Open
chaosflaws opened this issue Aug 9, 2017 · 4 comments
Open

Alias and relative path problem #322

chaosflaws opened this issue Aug 9, 2017 · 4 comments
Labels

Comments

@chaosflaws
Copy link

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?

@chaosflaws chaosflaws changed the title Alias and relative path problem Alias and relative path problem Aug 9, 2017
@ikkez
Copy link
Member

ikkez commented Aug 9, 2017

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. 🤔

@xfra35
Copy link
Member

xfra35 commented Aug 9, 2017

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.

@xfra35
Copy link
Member

xfra35 commented Aug 9, 2017

@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.

@chaosflaws
Copy link
Author

@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.

@ikkez ikkez transferred this issue from bcosca/fatfree Dec 13, 2020
@ikkez ikkez added the v4 label Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants