Dima Turchenko Posted January 20, 2017 Posted January 20, 2017 Hello! I am trying to develop some plugin and already did code hook successfuly but I dont know how send my own variables to output and use their. Can somebody point me in right direction? p.s. i had read developer documentation - seems its not obvious and easy
Ryan Ashbrook Posted January 20, 2017 Posted January 20, 2017 I'm not actually sure what it is you're asking - can you clarify, perhaps with some current code examples of what you are trying to accomplish?
Dima Turchenko Posted January 20, 2017 Author Posted January 20, 2017 Ok, lets do this step by step. Step 1. I have created code hook for admin controller IPS\core\modules\admins\members\members and set my own title like this class hook41 extends _HOOK_CLASS_ { public function members_groups() { \IPS\Output::i()->title = 'Members & Groups'; return \IPS\Theme::i()->getTemplate( 'members', 'core', 'admin' ); } } I want custom page in admin -> members section I had set template like above cause i had copy it from manage function of parent class, cause i dont know how to set my own template! Where actualy all templates place? Now i have empty page and this is no problem - but how i could send some variables to this legacy template (or using my custom template) ? Section in Plugins " Using Templates " didnt help at all Pls, can anybody explain me how and where create my own template where i could use my vars using simple explanation (or show me some tutorials where i could learn) And I had trying to debug IPS code but its not helped me a lot.
bfarber Posted January 20, 2017 Posted January 20, 2017 My take is that you have some controller code and you now want to show output, and are asking how to send the variables from your controller to the template. Most singletons can be accessed in templates already without the need to pass anything. i.e. in a template you can do this {expression="\IPS\Member::loggedIn()->name"} ...although this is a bad example because you can also just do {member="name"} but more generally speaking in a controller you would do this: \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'templateGroup' )->templateName( $variable1, $variable2 ); Then in your template you start the template with <ips:template parameters="$variable1, $variable2" /> Within the template you can then access those variables. This article describes using templates with plugins: If I've misunderstood please let me know though!
bfarber Posted January 20, 2017 Posted January 20, 2017 Sorry, our replies crossed. Your method is returning a template group object, so you could do something like $something = $this->members_groups(); \IPS\Output::i()->output .= $something->templateName( $variable1, $variable2 ); I'm not really sure where you copied the code you supplied from, as it isn't common for us to return a template group, but it's irrelevant. The main point here is if you want to output something you typically need to Assign the HTML you want to output to \IPS\Output::i()->output (note that we typically concatenate the output using .= so if something else outputs before or after it all gets put together into a single page, rather than wiping out previous HTML stored to output). \IPS\Theme::i()->getTemplate( 'members', 'core', 'admin' ); will return a template group. Specifically in developer mode this relates to the applications/core/dev/html/admin/members folder. You then call against the template in this group which relates to a file in the folder, without the .phtml extension, and you can pass the variables in to the call. i.e. \IPS\Theme::i()->getTemplate( 'members', 'core', 'admin' )->adminDetails( $variableHere ); Does that help?
Dima Turchenko Posted January 20, 2017 Author Posted January 20, 2017 Thanks for answers but i guess i need a bit little steps 1)Where I need to put my own template file and how it need look like? For example, usual framework solution would be controllers test -- namespace helloController heyAction views test - namespace hello hey.phtml In controller I could do something like $this->view->add('some_var' => $some_var); $this->view->render(); So here I put my template file in views/test/hello/hey.phtml and send var with name 'some_var' Where I need put my own "view" file in IPS while develop plugin (actualy for section admin - members ) ?
Daniel F Posted January 20, 2017 Posted January 20, 2017 It's described in our tutorial Quote Fortunately, creating a HTML template is really easy. If you look into the directory on your computer/server where IPS Community Suite is installed, you'll notice a "plugins" directory - inside this you'll find a directory has been created for your plugin with the name you specified in Step 1. Inside this is a folder navigate to dev/html. Within this folder, files you create will become available as a template.
Dima Turchenko Posted January 20, 2017 Author Posted January 20, 2017 Thats why I mention that tutorial not clearly. Guys if it would i didnt write here post cause for me not undertanable why any templates are in DEV directory!
newbie LAC Posted January 20, 2017 Posted January 20, 2017 Hello, 55 minutes ago, Dima Turchenko said: public function members_groups() You can't use underscore here in method name 2. If you create a plugin your phtml templates stored in plugins/%plugin_name%/dev/html/ Example plugins/myPlugin/dev/html/myTemplate.phtml Then your code will be something like this public function membersGroups() { \IPS\Output::i()->title = 'Members & Groups'; \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' )->myTemplate(); } Page url admin/?adsess=123abc&app=core&module=members&controller=members&do=membersGroups
Dima Turchenko Posted January 20, 2017 Author Posted January 20, 2017 35 minutes ago, newbie LAC said: Hello, You can't use underscore here in method name 2. If you create a plugin your phtml templates stored in plugins/%plugin_name%/dev/html/ Example plugins/myPlugin/dev/html/myTemplate.phtml Then your code will be something like this public function membersGroups() { \IPS\Output::i()->title = 'Members & Groups'; \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'plugins', 'core', 'global' )->myTemplate(); } Page url admin/?adsess=123abc&app=core&module=members&controller=members&do=membersGroups Thank u very much! I have did that, finally! Now I am understood that all templates saved in dev folders
Recommended Posts
Archived
This topic is now archived and is closed to further replies.