![]() |
Parse handlebar help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Parse handlebar help (/showthread.php?tid=68032) |
Parse handlebar help - MoFish - 05-13-2017 Hi, I have an empty view with the following mark-up inside. Code: {{ edit|codeignitor }} I am trying to find every instance of {{edit}} in my view and then create a record in the database with the second parameter which i pass in, in this case is 'codeignitor'. {{edit|codeignitor}}. Database stuff aside (thats the long term goal) I set out coding and got a little confused on how best to parse the handlebars. I started by loading the view into a variable named $html PHP Code: $html = $this->load->view("web/layouts/" . $data['data']->template, '', true); I then figured doing a preg_match_all to find the {{edit}} tags would be a good starting point, however struggled with this part, and dont have much of an idea how to best find the string after the pipe. ![]() PHP Code: preg_match_all('~\{(.*?)\}~', $html, $matches); Could anyone give me any guidance on how best this can be done? Regards, MoFish RE: Parse handlebar help - dmyers - 05-13-2017 CodeIgniter supports the handlebars / data replacement (their single by default format) using the CodeIgniter Template Parser Class: https://www.codeigniter.com/user_guide/libraries/parser.html If you are referring to handlebars via Handlebars JS http://handlebarsjs.com/ then I highly recommend https://github.com/zordius/lightncandy Unless you are trying to create something yourself? I always recommend that for learning but in the end using a library with multiple contributors and support is usually best. DMyers |