Skip to content

Instantly share code, notes, and snippets.

@jeffreyvr
Created March 6, 2018 14:49
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 jeffreyvr/0097341c36300788b3aac4826adf2ca4 to your computer and use it in GitHub Desktop.
Save jeffreyvr/0097341c36300788b3aac4826adf2ca4 to your computer and use it in GitHub Desktop.
Simple helper class for Mjml.
<?php
namespace App\Helpers;
use Config;
class MjmlHelper
{
public static function auth() {
if ( empty( env('MJML_APPID') ) || empty( env('MJML_APPSECRET') ) ) return;
return base64_encode(env('MJML_APPID').':'.env('MJML_APPSECRET'));
}
public static function call( $method, $args = array() ) {
$auth = self::auth();
if ( empty( $auth ) ) return;
$ch = curl_init();
$headers = [
'Content-Type:application/json',
'Authorization: Basic '. self::auth()
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,"https://api.mjml.io/v1/" . $method);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(build_post_fields($args)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
$response = json_decode( $server_output );
if ( isset( $args['abort_on_error'] ) ) {
self::is_error( $response );
}
return $response;
}
public static function is_error( $response ) {
if ( !empty( $response->errors ) ) {
foreach ( $response->errors as $error ) {
echo 'L:' . $error->line . ': ' . $error->message . '<br>';
}
abort();
}
}
}
@vascubrian
Copy link

Hello, any one can help
my app.js

app.onPageInit('index', function (page) {
// Do something here for "about" page
var template = $$('#index').html();
var compiledTemplate = Template7.compile(template);
app.request.get('localhost/*****/home/TestAjax', function (data) {
var context = data;
var html = compiledTemplate(context);
});
}).trigger();

my view

<script id="index" type="text/template7"> Hello, my name is {{firstName}} {{lastName}} </script>

its not working

@jeffreyvr
Copy link
Author

jeffreyvr commented Aug 9, 2018

@vascubrian This gist has nothing to do with Template7 but with MJML. Looking at your code, it seems related to Template7 (from Framework7). Your best option is to seek help at http://forum.framework7.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment