Skip to content

Commit 8c4d311

Browse files
Update render attributes (#273)
1 parent 1e56f37 commit 8c4d311

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

src/editor-controls/control-hover-animation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
110110

111111
$this->add_render_attribute( 'wrapper', 'class', $elementClass );
112112
?>
113-
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
113+
<div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
114114
...
115115
</div>
116116
<?php

src/editor-controls/control-url.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
155155
$this->add_link_attributes( 'website_link', $settings['website_link'] );
156156
}
157157
?>
158-
<a <?php echo $this->get_render_attribute_string( 'website_link' ); ?>>
158+
<a <?php $this->print_render_attribute_string( 'website_link' ); ?>>
159159
...
160160
</a>
161161
<?php

src/widgets/rendering-html-attribute.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Let's look at a simple widget output:
1616

1717
## PHP Render Attribute
1818

19-
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()`:
19+
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()`:
2020

2121
```php
2222
<?php
@@ -32,16 +32,27 @@ protected function render() {
3232
'aria-label' => $settings['name'],
3333
]
3434
);
35+
36+
$this->add_render_attribute(
37+
'inner',
38+
[
39+
'class' => 'custom-widget-inner-class',
40+
'data-custom' => 'custom-widget-information',
41+
]
42+
);
3543
?>
36-
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>> ... </div>
44+
<div <?php echo $this->get_render_attribute_string( 'wrapper' ); ?>>
45+
<div <?php $this->print_render_attribute_string( 'inner' ); ?>>
46+
...
47+
</div>
48+
</div>
3749
<?php
38-
3950
}
4051
```
4152

4253
## JS Render Attribute
4354

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

4657
```php
4758
<?php
@@ -57,8 +68,19 @@ protected function content_template() {
5768
'aria-label': settings.name,
5869
}
5970
);
71+
view.addRenderAttribute(
72+
'inner',
73+
{
74+
'class': 'custom-widget-inner-class',
75+
'data-custom': 'custom-widget-information',
76+
}
77+
);
6078
#>
61-
<div {{{ view.getRenderAttributeString( 'wrapper' ) }}}> ... </div>
79+
<div {{{ view.getRenderAttributeString( 'wrapper' ) }}}>
80+
<div {{{ view.getRenderAttributeString( 'inner' ) }}}>
81+
...
82+
</div>
83+
</div>
6284
<?php
6385
}
6486
```

src/widgets/rendering-inline-editing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ class Elementor_Test_Widget extends \Elementor\Widget_Base {
108108
$this->add_inline_editing_attributes( 'description', 'basic' );
109109
$this->add_inline_editing_attributes( 'content', 'advanced' );
110110
?>
111-
<h2 <?php echo $this->get_render_attribute_string( 'title' ); ?>><?php echo $settings['title']; ?></h2>
112-
<div <?php echo $this->get_render_attribute_string( 'description' ); ?>><?php echo $settings['description']; ?></div>
113-
<div <?php echo $this->get_render_attribute_string( 'content' ); ?>><?php echo $settings['content']; ?></div>
111+
<h2 <?php $this->print_render_attribute_string( 'title' ); ?>><?php echo $settings['title']; ?></h2>
112+
<div <?php $this->print_render_attribute_string( 'description' ); ?>><?php echo $settings['description']; ?></div>
113+
<div <?php $this->print_render_attribute_string( 'content' ); ?>><?php echo $settings['content']; ?></div>
114114
<?php
115115
}
116116

0 commit comments

Comments
 (0)