I am creating a small templating engine for our internal purpose. We have a several HTML templates that contains tokens in the form {token.name.value}. We submit it to the backend which then does its thing and replaces the tokens with their corresponding value. But, that is a long process and there is a lot of back n forth in case a template is not working.
So, I am thinking of having all the tokens as {key:value} pair in the database or a json file. Then we can select the template and the json dictionary file and the application can replaces the tokens in the template using the dictionary file and show us the output.
I can do the rest but I am not sure how can I go about replacing the tokens in the template. How should I parse the html template? Is using preg_replace function recommended?
Thanks.