[wp-trac] [WordPress Trac] #29988: Twenty Fifteen: Use JS/postMessage to update the color scheme instead of triggering a page refresh
WordPress Trac
noreply at wordpress.org
Thu Nov 6 07:34:03 UTC 2014
#29988: Twenty Fifteen: Use JS/postMessage to update the color scheme instead of
triggering a page refresh
------------------------------------+-----------------------------
Reporter: avryl | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Bundled Theme | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses: javascript
------------------------------------+-----------------------------
Comment (by westonruter):
@bradyvercher: Your approach is ideal. There should be no need for any
“`partialRefresh`” just to apply some PHP data to a template to then
inject into the Customizer preview. So using JS templates to dynamically
build these stylesheets on the client is definitely the way to go.
I don't see in your patch, however, that the template is being used for
rendering out the template in PHP as well? That's the sticky point I think
when trying to do JS templating and keeping things DRY: there is no
language-agnostic template language in Core, like Mustache. Your
Underscore template looks like a strict subset of the syntax available, so
it would be straightforward to implement a Underscore.js template subset
parser in PHP and re-use the template for rendering out the stylesheet
outside the context of the Customizer.
The PHP template processor could be as simple as:
{{{#!php
<?php
$underscore_tpl = '/* ... */';
$tpl_vars = array( /* ... */ );
$search_replace = array();
foreach ( $tpl_vars as $key => $value ) {
$search_replace[ "{{ data.$key }}" ] = $value;
}
$stylesheet = str_replace( array_keys( $search_replace ), array_values(
$search_replace ), $underscore_tpl );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29988#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list