![]() |
Anyone have a library to parse users input for variables or macros? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Anyone have a library to parse users input for variables or macros? (/showthread.php?tid=63109) |
Anyone have a library to parse users input for variables or macros? - jLinux - 09-27-2015 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 RE: Anyone have a library to parse users input for variables or macros? - jLinux - 09-27-2015 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 RE: Anyone have a library to parse users input for variables or macros? - mwhitney - 09-28-2015 You could probably adapt a template library (like Twig, Smarty, or Plates) for your purposes. |