Anyone have a library to parse users input for variables or macros? |
In the application I'm in the middle of developing, there are many instances where it would be useful for a user to be able to use "variables" in the input of whatever is being created.
For example, admins/moderators can create "pages" in the application, and lets say they wanted to display the name of the page inside the page content, it would be useful if they could just put something like {{page_title}}, and at runtime, have the name of the page be displayed. If every instance of where these "variables" would be used, they were just string to string replacements, (such as my example above), then a simple preg_replace or str_replace would suffice... However, I need something a little more complicated. Lets say they want to do something like display the email address of the account with the username demouser, then they should be able to use something similar to {{demouser[email]}}. Some other examples of what would/could be used...
Thank you
I messed around for a bit and came up with something simple, pasted below. If anyone has something better or more stable, then let me know please.. Or something specific to CI.
PHP Code: <?php
You could probably adapt a template library (like Twig, Smarty, or Plates) for your purposes.
|
Welcome Guest, Not a member yet? Register Sign In |