Frank Vèssia Posted March 29, 2020 Posted March 29, 2020 I'd like to add extra markup to a specific inputfield text in the admin using a module, I tried an hook like this but pw says the method doesn't exist $this->addHookBefore('Inputfield::render', $this, "addMarkup"); protected function addMarkup($event){ $Inputfield = $event->object; if($Inputfield->attr('name') == "myfieldname"){ $Inputfield->setMarkup([ 'item_content' => "my markup" ]); } }
bernhard Posted March 29, 2020 Posted March 29, 2020 If you hook the render() method, the $event->return contains the markup. Therefore you need to modify $event->return to modify the markup: 3
gmclelland Posted March 29, 2020 Posted March 29, 2020 @bernhard off topic, but what is RockBodyBuilder?
jploch Posted June 5 Posted June 5 (edited) Just adding this here as note for me and others. There is also an alternative way to append custom markup to an inputfield: $inputfield->appendMarkup('<div class="test">Hello</div>'); Edited June 5 by jploch Sorry the original post didn’t make much sense. I corrected my post 1
Robin S Posted June 5 Posted June 5 36 minutes ago, jploch said: Just adding this here as note for me and others. There is also a much simpler way to add custom markup to an inputfield: $field->appendMarkup('<div class="test">Hello</div>'); Which approach to take depends on where you want the added markup to appear, relative to things like description and notes. Demo: $wire->addHookBefore('InputfieldText::render', function(HookEvent $event) { /** @var InputfieldText $inputfield */ $inputfield = $event->object; if($inputfield->name !== 'text_1') return; $inputfield->prependMarkup('<div>prependMarkup</div>'); $inputfield->appendMarkup('<div>appendMarkup</div>'); }); $wire->addHookAfter('InputfieldText::render', function(HookEvent $event) { /** @var InputfieldText $inputfield */ $inputfield = $event->object; if($inputfield->name !== 'text_1') return; $event->return = '<div>before render</div>' . $event->return . '<div>after render</div>'; }); Related request: https://github.com/processwire/processwire-requests/issues/536 4
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now