Templating app.html
See original GitHub issueDescribe the problem
Currently SvelteKit templating is fairly simple: it replaces %svelte.head%
and %svelte.body%
entries in app.html
.
However, sometimes it is necessary to augment some parts of app.html
that are outside of Svelte’s control.
For example, for i18n one needs to be able to change the lang
attribute on <html>
or set a class on <body>
tag.
Describe the proposed solution
It would be useful if SvelteKit provided some built-in templating solution for app.html
that extends beyond replacing %svelte.head%
and %svelte.body%
and provides access other request parameters.
Alternatives considered
It is possible to do such templating in handle
hook. For example, we can define some logic in app.html
in EJS format and then run the templating engine on response.body
before returning it from the hook.
Importance
would make my life easier
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:8 (1 by maintainers)
transformPage
is the recommended way to inject values into HTML outside Svelte’s control — e.g.:Closing this as I don’t think there’s a way to make this more convenient without cluttering the API with something less flexible
it can be done with svelte:body but with a lot of limitations right now, but there is an open issue for that: https://github.com/sveltejs/svelte/issues/3105. For the
<html>
you can’t but any attributes beforehand in the app.html file that need to change for this to work. I use it like this in my project :