We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Is it possible to assign dynamic values to an attribute? for example
x-data = { href: '{{post_permalink}}' }
I am trying to use it inside a loop.
The text was updated successfully, but these errors were encountered:
Doesn't look like it, there is no filter in place. I suppose there could be one here:
attributes-for-blocks/attributes-for-blocks.php
Line 163 in 42e73d1
So replace it with:
return apply_filters('afb_get_attributes', $attributes, $args, $tags);
(I'll include it in the next release so it won't disappear with a plugin update) and then you can use something like:
add_filter('afb_get_attributes', function($attributes) { foreach($attributes as $key => $value) { $attributes[$key] = str_replace('{{my_dynamic_permalink}}', esc_js(get_the_permalink()), $value); } return $attributes; });
Alternatively you could locate the dynamic value with AlpineJS on the page, if it's available:
<!-- wp:query --> <div class="wp-block-query"> <!-- wp:post-template --> <!-- wp:post-title {"isLink":true,"attributesForBlocks":{"x-cloak":""}} /--> <!-- wp:post-date {"attributesForBlocks":{"x-data":"{href: $el.previousElementSibling.querySelector('a').getAttribute('href')}","x-text":"href"}} /--> <!-- /wp:post-template --> </div> <!-- /wp:query -->
Sorry, something went wrong.
No branches or pull requests
Is it possible to assign dynamic values to an attribute? for example
I am trying to use it inside a loop.
The text was updated successfully, but these errors were encountered: