Welcome Guest, Not a member yet? Register   Sign In
Call function when template variable or substring found
#1

[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
#2

[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.
#3

[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-gui...arser.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.




Theme © iAndrew 2016 - Forum software by © MyBB