[buddypress-trac] [BuddyPress Trac] #6921: Maybe introduce PHP Mustache parser for email templates

buddypress-trac noreply at wordpress.org
Thu Feb 18 09:45:54 UTC 2016


#6921: Maybe introduce PHP Mustache parser for email templates
------------------------------+----------------------------
 Reporter:  DJPaul            |      Owner:
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Future Release
Component:  Component - Core  |    Version:
 Severity:  normal            |   Keywords:
------------------------------+----------------------------
 From #6915

 Idea is to be able to conditionally render emails tokens without having to
 mix PHP conditionals into the templates; would also allow more
 customisation ability in the email content.

 @ray did some investigation which I'm going to quote here, and attach his
 patch:
 ----

 > I'd rather take the time to consider replacing the basic/simple token
 parsing logic with a real Mustache template parser.

 I think this would be very cool and quite easy to integrate.

 Only question is what Mustache parser we would want to use.

 * [https://github.com/bobthecow/mustache.php mustache.php] is linked from
 the official mustache Github page.  Could use Composer for this, but
 library is 176kb.
 * [https://github.com/zordius/lightncandy LightnCandy] claims to be 2-7
 times faster than mustache.php, but requires PHP 5.3 due to namespaces.
 Library is also 196kb.

 For `6915.mustache.patch`, I decided to pick a lesser-known library,
 [https://github.com/KiNgMaR/php-mustache php-mustache], that is only 40kb
 and licensed under the BSD.  We can pick and choose any library, I just
 chose one that was relatively small.

 To address the issue in this ticket, I've included some unit tests for
 `bp_core_replace_tokens_in_text()` and have changed the email template to
 use a mustache section for the unsubscribe block -- `{{#unsubscribe}}`.
 The `'unsubscribe'` token is only added if the user is active.  See the
 changes made to `bp_email_set_default_tokens()` and `bp_is_user_active()`.

 Now, the unsubscribe link will not show up in registration and activation
 emails.

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6921>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list