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

th:include/replace to allow server root relative URLs #554

Closed
rattek opened this issue Nov 10, 2016 · 6 comments
Closed

th:include/replace to allow server root relative URLs #554

rattek opened this issue Nov 10, 2016 · 6 comments

Comments

@rattek
Copy link

rattek commented Nov 10, 2016

The following to example refers to the same template hosted in my Spring project.

<th:block th:include="my/relative/uri" />
<th:block th:include="/my/relative/uri" />

However, I would like the first one to be relative to my project (http://mydomain.com/myproject/my/relative/uri) but the second to be relative to my server (http://mydomain.com/my/relative/uri).

In fact it's the same as for @{...} and @{~...}. This way, I could share template across my server.
Thank you to considerate!

@destan
Copy link

destan commented Nov 12, 2016

@rattek including fragments is local and nothing to do with domains or URLs. You can think of this process like reading a local file from classpath. So it's not relevant to try including fragments via your app's web URL.

Take a look here http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#fragment-specification-syntax for some examples.

@danielfernandez
Copy link
Member

As @destan correctly explained, template resolution is a configurable process independent of the URLs that your web server / web application is configured to respond to. Please have a look at the corresponding tutorial chapters on Template Layout to better understand this process.

@rattek
Copy link
Author

rattek commented Nov 14, 2016

Thank you very much for the answers!! I was wondering that "UrlTemplateResolver" has been created especially for getting template that are not within the same application. To me it makes a lot of sense to share templates globally (for many applications). Do you know if there's a way to do so? Thanks again!!

@ultraq
Copy link
Member

ultraq commented Nov 14, 2016

I have heard of people sharing templates across a network (I had one dev let me know that an in-development version of the layout dialect was really slow for them because they accessed templates across a network), so I think if your templates are served as HTML via any plain old HTTP web server, you can access it using that UrlTemplateResolver.

@rattek
Copy link
Author

rattek commented Nov 15, 2016

Yes, this is exactly what I've done. UrlTemplateResolver worked as expected but it's not as portable as I wish ... It could be awesome to have a "DomainTemplateResolver" (or ServerRootTemplateResolver) which can take into account path starting with slash as I've described in by initial post. Thank you for taking my suggestion into consideration.

@vimalcsolanki
Copy link

@rattek
Faced the same issue today while migrating from 2.1.3 to 3.0.9.
It started working fine again when I kept order of UrlTemplateResolver to the minimum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants