Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
PurplePixel Posted November 17, 2020 Posted November 17, 2020 (edited) Hey all, I'd like to add an additional variable to a Form Helper - Ideally I would like achieve this using a plugin only. Example: Making the `IPS\Helpers\Form\Number` to be responsive as the input currently have the `ipsField_short` class hardcoded for some reason making the handling of this field quite difficult. It's completely out of sync with the rest of the form helpers/elements. Approach is with a New Plugin: - Code Hook into `IPS\Helpers\Form\Number` to replacing the `html` method adding `$this->options['class']` to the very end (making it compatible with official version) - Same Code Hook redefining `$defaultOptions` with additional class element. - Theme Hook to `core/global/forms/number.phtml` selecting the `<input>` and completely replacing it with my own. Basically the same markup but replacing `class='ipsField_short'` with `class={$class}`. This makes it completely compatible with the original Number field but I can actually change the class of the number input field. My question is: how can add the additional class variable/parameter to `<ips:template parameters..` with a plugin? Thanks in advance Edited November 17, 2020 by PurplePixel typo
Solution bfarber Posted November 18, 2020 Solution Posted November 18, 2020 Instead of trying to add an additional parameter input to a template (which would be challenging, but doable), I'd instead just duplicate the template in your plugin and add the additional parameter there. That said, if you're bent on adding an additional parameter to the existing template (keep in mind a future update could cause all sorts of weird things to happen if you do this, so be prepared to maintain this plugin), you can redefine the entire method in a theme hook file. Create a theme hook on the appropriate area, and then redefine the template method in the theme hook file. Semi-example here where I overwrote the calendar view template group for an app: //<?php /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { exit; } class locator_hook_calendar_event_view extends _HOOK_CLASS_ { /* !Hook Data - DO NOT REMOVE */ public static function hookData() { return parent::hookData(); } /* End Hook Data */ public function view( $event, $commentsAndReviews, $attendees, $address=NULL, $reminder=NULL ) { \IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'calendar.css', 'locator', 'front' ) ); \IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_calendar.js', 'locator', 'front' ) ); return \IPS\Theme::i()->getTemplate( 'calendar', 'locator' )->view( $event, $commentsAndReviews, $attendees, $address, $reminder ); } } As you can see, I overwrote the PHP method generated by the template files...you could use this approach to add the new parameter. PurplePixel 1
Recommended Posts