Skip to content

Instantly share code, notes, and snippets.

@shramee
Created February 16, 2019 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shramee/96948c6e69448595ef59ce44cf1b9c12 to your computer and use it in GitHub Desktop.
Save shramee/96948c6e69448595ef59ce44cf1b9c12 to your computer and use it in GitHub Desktop.
Duplicates code in TPL replacing vars appropriately.
$tpl = <<<JS
// region BlkTitle
CaxtonBlock( {
id: 'woobuilder-blocks/BlkID',
title: 'BlkTitle',
icon: 'layout',
category: 'woobuilder',
apiUrl: function ( props ) {
var
attr = props.attributes,
qry = '';
return {
apiData: '/woobuilder_blocks/v1/Blk_ID?' + qry,
};
},
apiCallback: function ( props, that ) {
if ( props.apiData.data && props.apiData.data.html ) {
return Caxton.html2el( props.apiData.data.items.join( '' ), {
key: 'product-category-grid',
className: 'woobuilder-BlkID',
style: {},
onClick: function ( e ) {
e.preventDefault();
}
} );
} else {
return wp.element.createElement( 'div', {
className: 'caxton-notification',
key: 'notice'
}, 'Loading BlkTitle...' );
}
},
fields: {
// 'Text color': {
// type: 'color',
// default: '#fff',
// section: 'Typography',
// },
},
} );
// endregion BlkTitle
JS;
echo '<pre>';
foreach (
[
[ 'add_to_cart', 'add-to-cart', 'WooBuilder: Add to cart', ],
[ 'product_price', 'product-price', 'WooBuilder: Product price', ],
[ 'excerpt', 'excerpt', 'WooBuilder: Product Excerpt', ],
[ 'meta', 'meta', 'WooBuilder: Product Meta', ],
[ 'tabs', 'tabs', 'WooBuilder: Product Tabs', ],
] as $blk
) {
echo str_replace( [ 'Blk_ID', 'BlkID', 'BlkTitle' ], $blk, $tpl );
}
echo '</pre>';
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment