Welcome Guest, Not a member yet? Register   Sign In
Parse handlebar help
#1

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.  Huh

PHP Code:
preg_match_all('~\{(.*?)\}~'$html$matches); 

Could anyone give me any guidance on how best this can be done?

Regards,

MoFish
Reply
#2

CodeIgniter supports the handlebars / data replacement (their single by default format) using the CodeIgniter Template Parser Class: https://www.codeigniter.com/user_guide/l...arser.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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB