Skip to content

Commit

Permalink
Update render attributes (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-elementor authored Apr 16, 2024
1 parent 1e56f37 commit 8c4d311
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/editor-controls/control-hover-animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {

$this->add_render_attribute( 'wrapper', 'class', $elementClass );
?>
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
<div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
...
</div>
<?php
Expand Down
2 changes: 1 addition & 1 deletion src/editor-controls/control-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
$this->add_link_attributes( 'website_link', $settings['website_link'] );
}
?>
<a <?php echo $this->get_render_attribute_string( 'website_link' ); ?>>
<a <?php $this->print_render_attribute_string( 'website_link' ); ?>>
...
</a>
<?php
Expand Down
32 changes: 27 additions & 5 deletions src/widgets/rendering-html-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Let's look at a simple widget output:

## PHP Render Attribute

Using the `render()` method, we can add attributes to the HTML tag using `add_render_attribute()` and retrieve the attribute using `get_render_attribute_string()`:
Using the `render()` method, we can add attributes to the HTML tag using `add_render_attribute()`, retrieve the attributes using `get_render_attribute_string()`, and print attributes using `print_render_attribute_string()`:

```php
<?php
Expand All @@ -32,16 +32,27 @@ protected function render() {
'aria-label' => $settings['name'],
]
);

$this->add_render_attribute(
'inner',
[
'class' => 'custom-widget-inner-class',
'data-custom' => 'custom-widget-information',
]
);
?>
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>> ... </div>
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
<div <?php $this->print_render_attribute_string( 'inner' ); ?>>
...
</div>
</div>
<?php

}
```

## JS Render Attribute

Using the `content_template()` method, we can add attributes to the HTML tag using `addRenderAttribute()` and retrieve the attribute using `getRenderAttributeString()`:
Using the `content_template()` method, we can add attributes to the HTML tag using `addRenderAttribute()`, and retrieve the attribute using `getRenderAttributeString()`:

```php
<?php
Expand All @@ -57,8 +68,19 @@ protected function content_template() {
'aria-label': settings.name,
}
);
view.addRenderAttribute(
'inner',
{
'class': 'custom-widget-inner-class',
'data-custom': 'custom-widget-information',
}
);
#>
<div {{{ view.getRenderAttributeString( 'wrapper' ) }}}> ... </div>
<div {{{ view.getRenderAttributeString( 'wrapper' ) }}}>
<div {{{ view.getRenderAttributeString( 'inner' ) }}}>
...
</div>
</div>
<?php
}
```
6 changes: 3 additions & 3 deletions src/widgets/rendering-inline-editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
$this->add_inline_editing_attributes( 'description', 'basic' );
$this->add_inline_editing_attributes( 'content', 'advanced' );
?>
<h2 <?php echo $this->get_render_attribute_string( 'title' ); ?>><?php echo $settings['title']; ?></h2>
<div <?php echo $this->get_render_attribute_string( 'description' ); ?>><?php echo $settings['description']; ?></div>
<div <?php echo $this->get_render_attribute_string( 'content' ); ?>><?php echo $settings['content']; ?></div>
<h2 <?php $this->print_render_attribute_string( 'title' ); ?>><?php echo $settings['title']; ?></h2>
<div <?php $this->print_render_attribute_string( 'description' ); ?>><?php echo $settings['description']; ?></div>
<div <?php $this->print_render_attribute_string( 'content' ); ?>><?php echo $settings['content']; ?></div>
<?php
}

Expand Down

0 comments on commit 8c4d311

Please sign in to comment.