I am trying to build a basic templating engine. Like the template engines already available as open source, I am using search and replace techniques.
However, as the search and replace have to be hardcoded, it is not so much flexible. What I mean to say is, as an example, I am using something like this
$templateMarkup = '<div class="title">{_TITLE_}</div>';
$renderedMarkup = str_replace("{_TITLE_}",$title,$templateMarkup);
echo $renderedMarkup;
As you can see, it is hardcoded. So I have to purposely know all the placeholders to accomplish a successful render.
I am a little bit weak in regular expression. But I know, if I can develop a regex, which can match all the text starting with {_
and ending _}
and get the value in between them, I just might be able to create a flexible templating engine.
I need help with the regular expression.
If I am completely going the wrong way to accomplish, please do warn me.
For those who think I am reinventing the wheel. Here is my explanation
Templating engines, that are already available are quite unnecessarily complex.
My requirements are simple and so I am builidng my own simple engine.