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.
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