Skip to content

Include an .html file wholesale #148

@biruburu

Description

@biruburu

Is there a way to split the rsx content into a dedicated .html file and include it to be parsed in hypertext? Based on the rsx-htmx example, something like this:

document.rs:

use hypertext::prelude::*;

use crate::views::nav::Nav;

#[component]
pub fn document<'a, R: Renderable>(selected: &'a str, children: &R) -> impl Renderable {
    rsx!("document.html")
}

document.html:

<!DOCTYPE html>
<html>

<head>
    <title>"Hypertext - HTMX with RSX"</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/htmx.org@2"></script>
    <link rel="stylesheet" href="/styles.css">
</head>

<body class="bg-gray-900 text-gray-100">
    <h1 class="flex text-5xl mx-auto font-bold justify-center items-center mb-2">Hypertext</h1>
    <Nav selected=selected oob=true />
    <div id="page" class="mt-2">
        (children)
    </div>
</body>

</html>

This would give html formatting for free, including tailwind class sorting and all the other niceties from modern LSPs, as well as satisfy people who are allergic to mixing html inside rs files. (I'm not one of them, but I'm working with people who are refusing to look at hypertext because of that...) sqlx::query_file!() does something similar.

I'm not a macro expert, but would be happy to contribute if something like this would be interesting for hypertext.

In any case, awesome job on hypertext, this is by far my favourite rust templating library in terms of ergonomics and performance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions