Using template tags with data coming from a database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using template tags with data coming from a database (/showthread.php?tid=16160) |
Using template tags with data coming from a database - El Forum - 02-26-2009 [eluser]Marcelo Kanzaki[/eluser] Hello everybody, I've used CI to build a simple CMS where i can post articles that are stored in a database (so far so simple). People can submit new articles using a form: - Title [input text] - body [textarea] What i want is to be able to use template tags within my 'body' text coming from the database. So, i would post a new article but if i put {today} in the body, it would show a variable called $today behind the scenes. I tried with template parser but i couldn't. Any ideas? Using template tags with data coming from a database - El Forum - 02-26-2009 [eluser]pistolPete[/eluser] The template parser class ist the way to go, but it expects the view to be a local file. So you have to extend the parser class. The following code adds a method parse_string() to the parser class which allows you to parse a string coming from db. Code: class MY_Parser extends CI_Parser { Usage: Code: // the data which should be used instead of the {variables} The code is untested, so please report back if its working. Using template tags with data coming from a database - El Forum - 07-07-2009 [eluser]JulianM[/eluser] Thanks pistolPete. I needed something similar and was just thinking in create my MY_Parser until I saw this post [quote author="pistolPete" date="1235657288"]The template parser class ist the way to go, but it expects the view to be a local file. So you have to extend the parser class. The following code adds a method parse_string() to the parser class which allows you to parse a string coming from db. Code: class MY_Parser extends CI_Parser { |