Embeded Crystal costum path


I am making a program that is supposed to be able to generate a text file using Embedded Crystal.

What I want is that when you call the program the program should decide which template file it should be using. I want to do this by using string formatting.

Although it seems like the ERC class wants to select the file under compilation, not under run-time.
Is there away around this?

ECR is just fancy string interpolation. Since it’s a macro, it works in compile time. You can work it around with a switch case, by not passing a variable to the render method, but having a case..when structure, with a literal filename passed to ECR render in each branch.

I want to have something like 100 different templates, so A switch want really work.

Maybe you could use a macro for the switch.
Also, what about incorporating the differences and the logic into one single ECR file?

A single ECR wont work.

Perhaps a macro for the switch would work but I am a bit unsure how I would do that though.

Looks like you need a runtime template engine.

Maybe crinja fits for you. It’s a runtime template engine based on the Jinja2 syntax (I’m the author). It’s very powerful, but the syntax is quite readable

You could also look for other options at Template Engine on Shardbox

1 Like

I love jinja, thanks for doing a port for crystal, really means a lot.

And I will take a look at that.