Created
February 16, 2019 11:40
-
-
Save shramee/96948c6e69448595ef59ce44cf1b9c12 to your computer and use it in GitHub Desktop.
Duplicates code in TPL replacing vars appropriately.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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