Reputation: 2209
If I would like to implementent more sophisticated macro language to my CMS in PHP what would be the possible approach? Currently I have a macro resolver using preg_replace where you could call the macros in cms pages such as : {# GetPageName #} or {# GetUserName | UserID=9 #}, you get the idea.
The goal would be to use it in a way you could assign variables and use if statements such as: {# if GetPageName == 'Home' {'I am home page'} #} or {# var Name = GetCurrentUserName #}
Would something like this be possible?
Thank you for any insight.
Upvotes: 0
Views: 265
Reputation: 3359
It would definitely be possible to write your own macro language or template engine. The question is how much time you want to invest in this project and how ambitious you are about it general.
In most cases it is more productive to use something that is already there instead of reinventing the wheel. This way you can use and learn a sophisticated technology and once you've got the gist how it works you will be able to either write your own version of it or to modify what you have used so far and maybe you will end up contributing to an open source project which helps the whole community.
Take a look at Smarty for example but don't stop there. Do a bit of research to see what is available and to what extend it fits your use case.
Upvotes: 0