![]() |
Call function when template variable or substring found - 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: Call function when template variable or substring found (/showthread.php?tid=42418) |
Call function when template variable or substring found - El Forum - 06-07-2011 [eluser]ryan656[/eluser] Hey Everyone, I am working on a project with "Static Blocks" that the user can manage through the CMS. To embed them I just call the 'block' function I wrote and pass in the identifier of the block, which renders the HTML. This needs to be done inside the view file and what I really want is to allow the user to embed a template variable (something like {block=block_id}) and have the system call the block function on it's own. I know this isn't exactly a codeigniter thing but I wanted to see if anyone here could help me out. I have looked into call_user_func, eval, template parsing classes, output buffering and so on but I am confused becauese I feel like it shouldn't be that difficult and I am just missing something, but I really don't know. Any help would be much appreciated. Thanks, Ryan Call function when template variable or substring found - El Forum - 06-07-2011 [eluser]Johnny Freeman[/eluser] You could extend the Parser class to be able to parse this format {some_thing=some_value} and when "some_thing" is equal to block, call the block function. Shouldn't be too difficult. Call function when template variable or substring found - El Forum - 06-12-2011 [eluser]WanWizard[/eluser] Just noticed that the Parser library is not in the user guide index, but the documentation is there: http://ellislab.com/codeigniter/user-guide/libraries/parser.html. An alternative (which will require less work) is to get Dan Horrigan's simpletags library. It does something similar, but already supports tag parameters. You'll find it here: https://bitbucket.org/dhorrigan/simpletags/overview. You can then use the callback feature to process the 'blockname' and return the HTML for that block. |