admin管理员组文章数量:1122832
I've been working to update our custom gateway plugin to make use of the block checkout in WooCommerce.
I have managed to get the gateway to output but one of the settings fields we have takes raw html. This is now being rendered on the frontend as plaintext instead of rendering the HTML tags correctly.
I saw a few people mention a RawHTML
command but I'm not very familiar with how React works. Everything I have tried has resulted in either nothing being shown or a JS error. I am struggling to figure out how to get this section rendering correctly.
This is the JavaScript that I'm using to output the gateway:
const settings = window.wc.wcSettings.getSetting( 'gateway_data', {} );
const label = window.wp.htmlEntities.decodeEntities( settings.title ) || window.wp.i18n.__( 'Custom Gateway', 'custom_gateway' );
const Content = () => {
return window.wp.htmlEntities.decodeEntities( settings.description || '' );
};
const Block_Gateway = {
name: 'custom_gateway',
label: label,
content: Object( window.wp.element.createElement )( Content, null ),
edit: Object( window.wp.element.createElement )( Content, null ),
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings.supports,
},
};
console.log(Block_Gateway);
window.wc.wcBlocksRegistry.registerPaymentMethod( Block_Gateway );
Does anyone have any guidance on this?
I've been working to update our custom gateway plugin to make use of the block checkout in WooCommerce.
I have managed to get the gateway to output but one of the settings fields we have takes raw html. This is now being rendered on the frontend as plaintext instead of rendering the HTML tags correctly.
I saw a few people mention a RawHTML
command but I'm not very familiar with how React works. Everything I have tried has resulted in either nothing being shown or a JS error. I am struggling to figure out how to get this section rendering correctly.
This is the JavaScript that I'm using to output the gateway:
const settings = window.wc.wcSettings.getSetting( 'gateway_data', {} );
const label = window.wp.htmlEntities.decodeEntities( settings.title ) || window.wp.i18n.__( 'Custom Gateway', 'custom_gateway' );
const Content = () => {
return window.wp.htmlEntities.decodeEntities( settings.description || '' );
};
const Block_Gateway = {
name: 'custom_gateway',
label: label,
content: Object( window.wp.element.createElement )( Content, null ),
edit: Object( window.wp.element.createElement )( Content, null ),
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings.supports,
},
};
console.log(Block_Gateway);
window.wc.wcBlocksRegistry.registerPaymentMethod( Block_Gateway );
Does anyone have any guidance on this?
Share Improve this question edited Apr 22, 2024 at 14:02 Burgi asked Apr 22, 2024 at 13:09 BurgiBurgi 4032 silver badges15 bronze badges1 Answer
Reset to default 2I had a breakthrough shortly after posting the original question (isn't that always the way?).
I reread this answer and realised what I needed to do to get the output rendered correctly.
- I created the
const
as described in the other answer.
const htmlToElem = ( html ) => wp.element.RawHTML( { children: html } );
- I tried adding the anonymous function to the
content
attribute but that just broke my JS and nothing would load. - Instead I directly referenced the
const
and passed it thesettings.description
object. This loaded everything as expected.
content: htmlToElem(settings.description),
本文标签: plugin developmentOutput HTML Tags In Gutenberg Block
版权声明:本文标题:plugin development - Output HTML Tags In Gutenberg Block 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309610a1934080.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论