Using template tags with data coming from a database |
[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?
[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.
[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 { |
Welcome Guest, Not a member yet? Register Sign In |