Reputation: 315
I am working on a custom widget and I want to add styling configuration to the widget. One small problem that I found is that the color control in live editing does not work (It will work for preview and after save then reload).
As shown below, Tab's title and content font color does not change in live editor.
When you click on preview, it works as expected.
I started with the sample code provided on the Elementor Developers page:
echo '<h2 class="title" style="color: ' . $settings['title_color'] . '"> .. </h2>';
However I am getting the same results as describe in the first section.
I then tried to pass parameters to css class, as suggested in this stack overflow post. Though it was successfully set, but it was not set correctly.
My php file:
echo "<p id='narrative' style=' --fontColor : ".$settings['content_color']."'></p>";
In my css file:
#narrative {color: var(--fontColor);}
I am not really sure what went wrong, greatly appreciate if anyone could point me to the right direction. Thank you.
Upvotes: 2
Views: 1283
Reputation: 315
After reading through the sample source code on Elementor Code Reference.
I found out that I missed out a two important steps:
$this->add_control(
'border_color',
[
'label' => __( 'Border Color', 'elementor' ),
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .title' => 'color: {{VALUE}};', <-- add selector
],
]
);
<# #>
instead of php in render().<h2 class="title"> .. </h2>';
Upvotes: 1