Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Ideas for creating template based plugins?

108 views
Skip to first unread message

Chris Talavera

unread,
Nov 14, 2023, 6:54:17 PM11/14/23
to Fat-Free Framework
So we recently started developing with F3 for our new version of our ecommerce software. In our previous version, we had some code that searched for the variable of $plugin within templates and then ran a function within that plugin (PHP Class) to render the output for that part of the template. For example, a plugin with the name of 'recaptcha' would be referenced in a template as $plugin[recaptcha]. The template parsing would search for the plugin variable, look within the brackets for the plugin name and then create a new instance of the class and call the render function of that class to generate the output.

Does anyone know the best way to do something like that within F3 so that we can create similar plugin classes that create new instances of a class and generate the output within templates for those plugins.

Thanks in advance and I apologize if this is a dumb question. We are just getting started with F3 and so far it's making the task of a ground up rework very manageable.

v.

unread,
Nov 16, 2023, 3:33:31 AM11/16/23
to Fat-Free Framework
I struggled with similar issues in the past. You are trying to get back from the view to the controller which goes against the MVC principle. 
Although I'm sure more apt developers than me can get this done, you should probably move the rendering part to the Controller.

What about having a function you can access from the controller that handles everything you need? 
Eg.: setting the plugin and handle the parsing?

Pseudocode: 
private function recaptcha_plugin_example{
  //do your php stuff
  $f->set("plugin", 'view/pluginname.html');
}

in your view you can check if the plugin variable is set, and if so import it
  <check if="{{ isset(@plugin) "><include href="{{ @plugin }}" /></check>

You can then call the recaptcha_plugin_example in the function that renders the page.

Chris Talavera

unread,
Nov 16, 2023, 4:38:39 AM11/16/23
to Fat-Free Framework
Thanks for the reply, I actually found a way using custom tags to make this work. Basically I define a <plugin name="recaptcha"> tag for instance that calls up a class that loads the plugin defined.

\Template::instance()->extend('plugin', 'Secure::run_plugin');

So far I am loving F3.

v.

unread,
Nov 16, 2023, 5:03:59 AM11/16/23
to Fat-Free Framework
awesome, please consider sharing how you did this.

Chris Talavera

unread,
Nov 16, 2023, 7:02:32 AM11/16/23
to Fat-Free Framework
Yeah, once I have it implemented I will share more information.

ethanpil

unread,
Apr 17, 2025, 12:47:45 PMApr 17
to Fat-Free Framework
Resurrecting this thread hoping for that follow-up..
Reply all
Reply to author
Forward
0 new messages