-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
At the moment the Routing component only supports absolute and domain-relative URLs, e.g.
http://example.org/user-slug/article-slug/comments and
/user-slug/article-slug/comments.
But I find it very useful to specify path-relative URLs that depend on the current request path. Lets say the client requests http://example.org/user-slug/article-slug/ and I want to generate a link to the comments of the same article.
Currently the resulting link would again duplicate the user-slug and article-slug -> /user-slug/article-slug/comments.
But it could be simplified to comments or ./comments.
One additional feature that could be implemented is a new twig function (besides url and path) lets call it subpath.
It fetches the variables of the current request, e.g. user-slug and article-slug internally and then generates such a relative URL. The advantage is you don't need to specify the variables of the current request again.
So simply {{ subpath('article_comments') }} is enough for the URL ./comments. But you can optionally overwrite some request variables with {{ subpath('article_comments', {'article': 'different-article-slug'} ) }} which would generate ../different-article-slug/comments (i.e. same user, but different article).
Thinking of it, the twig function is also a quite useful without the path-relative URLs. So these are basically two feature requests.
I already got an idea how to implement this but would like to get your feedback whether one of these features is also useful to others.