Skip to content

Reading templates from OUT_DIR #631

@maulerjan

Description

@maulerjan

Hi!

There's a pre-processing step in my project, where the templates are built using Vite. This happens inside a build script. The built templates are being output into the OUT_DIR of my crate.

There doesn't seem to be any way to refer to <OUT_DIR>/my-template.html.

What I already tried:

#[derive(Template)]
#[template(path = concat!(env!("OUT_DIR"), "/my-template.html"))]
struct MyTemplate { /* ... */ }

This doesn't work, as Rust doesn't expand the inner macro before passing it to the derive macro.

I think the cleanest solution would be to have an ability to specify some config options as compile-time environment variables (e.g. ASKAMA_BASE_PATH). I could then set this environment variable inside my build script, provided that Rust passes env vars into the procedural macro crates, which I don't know.

What are your opinions and does anyone have any other suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions