Generate leex template at run time

I’m programming an education game, possibly for phoenix phrenzy, and I’d like to create my leex template based on choices made on the web page. Is this simple? possible? sample code?

(Generating all of the combinations and selecting the appropriate one is certainly possible, but not my favorite solution.)

I’d probably use nested templates and some live view updated variables for which template to load for each section. On my phone so I can’t easily give a code sample, but basically change the template variable on the render function as needed.

1 Like

Yes, it is definitely possible. If you create a template file at run-time you can then run leex on it to generate a new scanner module which you then can compile and load. The scanner module is just a normal module so recompiling and reloading it is nothing strange.

In the Erlang/elixir system there are just modules. All modules are created equal, as are all processes are created equal and all applications are created equal. It is a very egalitarian system. :smile:

7 Likes