Skip to content

Add rsx_file! macro for external RSX template files#184

Closed
thefiddler wants to merge 1 commit intovidhanio:mainfrom
thefiddler:feature/rsx-file
Closed

Add rsx_file! macro for external RSX template files#184
thefiddler wants to merge 1 commit intovidhanio:mainfrom
thefiddler:feature/rsx-file

Conversation

@thefiddler
Copy link

@thefiddler thefiddler commented Mar 6, 2026

Closes #148

This MR adds two new macros, rsx_file! and rsx_file_borrow! mirroring rsx! and rsx_borrow!, that allow users to split html code into separate .html files if they wish. This enables formatting and linting support for free using the default IDE language servers e.g. in Zed or VSCode.

Design choices:

  • rsx_file! naming scheme for consistency with sqlxquery_file!
  • Template path is relative to CARGO_MANIFEST_DIR. Unlike askama, I opted to not force an implicit templates/ directory with askama.toml override, but rather let the user choose the complete path. But happy to change if we want to increase consistency with askama.
  • I use include_bytes! for dependency tracking so Cargo automatically recompiles when the template file changes
  • Basic validation that the path is not absolute
  • Basic testing

Example

  // templates/success.html
  <h1>"Success!"</h1>
  <p>"The operation completed successfully."</p>
  // src/lib.rs
  use hypertext::rsx_file;

  pub fn success_template() -> impl Renderable {
      rsx_file!("templates/success.html")
  }

Let me know your thoughts!

@thefiddler thefiddler force-pushed the feature/rsx-file branch 2 times, most recently from 1daa483 to 42b2ea0 Compare March 6, 2026 06:37
… files

Enables loading RSX templates from external files relative to CARGO_MANIFEST_DIR,
with include_bytes!-based dependency tracking for automatic recompilation.
@thefiddler
Copy link
Author

Closing in favour of #185

@thefiddler thefiddler closed this Mar 8, 2026
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

Successfully merging this pull request may close these issues.

Include an .html file wholesale

2 participants