The above code worked perfectly for my use case, and slightly jankily for yours (if I understand yours correctly).
In my use case, I am putting the template into an existing file using the “Open Insert Template modal” hotkey.
When I created a new file from the template running the above code (which I think is your use case, right?), it initially popped up with the dice-mod string in an inline codeblock–but as soon as I clicked into the body of the file, it replaced with the table result.
I think the reason it works is the double quotes within the Templater code string. Templater passes “text” directly into the page, so when we pass the dice-mod code string it shows up in the file, and then runs when we refresh the page.
I know this is a few months later, but I hope it helps you!
Tried to add this as an edit, but I had waited too long to edit apparently.
When I first responded it was working without any further intervention. Literally minutes later, I needed to swap between reading and editing mode to get the dice-mod code to run. I have no clue what I changed.
You can set it up to run the roll once each time the template is used. If you need more advanced functionality, you might want to check out a solution like dice online for more features and flexibility. This could simplify your setup and give you a variety of options to work with. Let me know if you need more details on setting this up!