Can you please tell me how to work with the getData method in the block?
Good evening guys! Can you please tell me how to work with the getData method in the block?
I have a translatable field where I need to get the last word and insert it separately into a block template.
public function getData(array $data, \A17\Twill\Models\Block $block): array
{
$data = parent::getData($data, $block);
$words = explode(' ', $block->translatedinput('title '));
**$data['last_word']** = array_pop($words);
return $data;
}
And here I need to get this element:
<h1 class="main-section_title"> {!! $block->translatedinput('title') !!}<br/><span class="text-accent-01">**{!! $block->translatedinput(last_word)** !!}</span></h1>
7 Replies
I need to substitute $data['last_word'] (I wanted to make it bold, but it didn't work😃 )
Hey @savchuk.ivan , what error are you receiving?
@Harings Rob Good evening. There are no errors. It just doesn't display the element. I have a suspicion that I incorrectly form the data.
$block->translatedinput('title')
will always return the whole thing, so you need to return 2 different variables to achieve what you want, I think@ifox
message: "Undefined variable $data
Now it throws an error.my bad, you should directly use the variable eg,
$last_word
@ifox Thank you very much. Now everything works correctly.