Template engine for elysia? #571
Unanswered
SercanBayram
asked this question in
Q&A
Replies: 3 comments 3 replies
-
Are you talking about engines like Nunjucks and Liquid? Express is not a template engine. |
Beta Was this translation helpful? Give feedback.
0 replies
-
use the elysiajs/html plugin |
Beta Was this translation helpful? Give feedback.
0 replies
-
I agree, // /layouts/Page.tsx
import { Html } from '@elysiajs/html';
export const Page = ({ title, children }: { title: string, children: Html.Children }) => (
<html>
<head>
<title>{title}</title>
</head>
<body>
<div id="root">{children}</div>
</body>
</html>
);
// /views/Home.tsx
export const Home = ({ fruit }: { fruit: string[] }) => {
return (
<>
<h1>Welcome Home</h1>
<p>Here are some fruits:</p>
<ul>
{fruit.map(f => <li>{f}</li>)}
</ul>
</>
);
};
// /index.tsx
import { Elysia } from 'elysia';
import { html } from '@elysiajs/html';
import { Page } from './layouts/Page.tsx';
import { Home } from './views/Home.tsx';
// Application
const app = new Elysia()
.use(html())
.get('/', () => {
return (
<Page title="Home">
<Home fruit={['🍎', '🍊', '🍇', '🍉', '🍌']} />
</Page>
);
})
.listen(3001);
// Debug
console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
how can i use template engine like express -handler for elysia? is there a module or method for this?
Beta Was this translation helpful? Give feedback.
All reactions