Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IDs (HTML Anchors) #41

Open
gettonet opened this issue Apr 4, 2020 · 2 comments
Open

Support IDs (HTML Anchors) #41

gettonet opened this issue Apr 4, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@gettonet
Copy link

gettonet commented Apr 4, 2020

Would be very useful if container or row would have an option to add id, along with class...Any chance of implementing this feature?

@tschortsch
Copy link
Member

Hi @gettonet. There was already a feature request to add an ID attribute to the blocks here: https://wordpress.org/support/topic/classes-being-added-to-the-block-outer-and-not-the-row/. As I wrote there in my opinion this should be a feature which should be added by Gutenberg itself. But since this doesn't seem to happen in the near future I will think about adding them to our blocks.

@tschortsch tschortsch added the enhancement New feature or request label Apr 4, 2020
@tschortsch tschortsch self-assigned this Apr 4, 2020
@forcecodema
Copy link

I agree that it would be nice feature to have - and it is easy to add it.
Let's say for the row block we may add blockId or elementId attribute in:

class-row-block-type.php

protected $attributes = array(
	'blockId' => array(
		'type' => 'string',
	),

the default value in the same file like:

protected $default_attributes = array(
	'blockId' => '',
	...

then in row/edit.js

const {
	blockId,
	...
} = attributes;
...
<PanelBody>
	<TextControl
		label="Block Id"
		value={ blockId }
		onChange={ ( value ) => {
			setAttributes( {
				blockId: value,
			} );
		} }
	/>
</PanelBody>
...

and finally modify templates/row.php

$blockId = "";
if ( array_key_exists( 'blockId', $attributes ) && !empty( $attributes['blockId'] ) ) {
	$blockId = 'id="' . esc_attr( $attributes['blockId'] ) . '"';
}

and

<div <?php echo $blockId; ?> class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants