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

Request: Ability to send locals to Pug template #595

Open
JL102 opened this issue Apr 30, 2023 · 0 comments
Open

Request: Ability to send locals to Pug template #595

JL102 opened this issue Apr 30, 2023 · 0 comments

Comments

@JL102
Copy link

JL102 commented Apr 30, 2023

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. For example: I'm always frustrated when [...]
I'm looking to port my existing web app from ExpressJS/Pug to SvelteKit, and it would be really helpful if I can use the Pug preprocessor to save us a lot of time, i.e. we could just copy the code over to our new Svelte files without having to rewrite everything to Svelte all at once. The issue preventing me from doing this is that we pass a lot of variables and functions into our Pug files, such as i18n code (e.g. div!=msg('index.hello') becomes <div>Hello world!</div>) and variables from the database. It seems like the Svelte code transformer doesn't pass any locales into the compiled Pug function, so I don't see a way to pass our i18n msg function into there.

Describe the solution you'd like
I would really like it if I can pass data into the template function. Maybe like this:

<script lang='ts'>
	
	import type { PageData } from './$types';
	import { msg } from '$lib/i18n';
	
	export let data: PageData;
	
</script>

<template lang="pug" locales={{
	data,
	msg
}}>
	
	if data.foo
		div!=msg('hello world')
	
</template>

Describe alternatives you've considered
For if / each statements, I imagine I could end the and do some Svelte if/each statements in between tags, but I don't think a solution like that could help with functions.

How important is this feature to you?
Vital. This would save an insane amount of time if I can pass locals to our Pug templates, because then we could keep the majority of our existing Pug code to start with, and then slooowly chip away at translating pages properly from Pug to Svelte, one at a time as-needed.

Additional context
If one of y'all can say that it's possible, but don't have the time yet to actually implement it, please let me know because I'd be willing to try and commit a contribution to implement this feature. But I'd rather not spend 5 hours poking through code and trying then to learn that it's not possible (it'd be easier to have a dev who knows how the preprocessing works who can probably say pretty easily if this is someting that's not possible.)

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

No branches or pull requests

1 participant