Created
March 6, 2018 14:49
-
-
Save jeffreyvr/0097341c36300788b3aac4826adf2ca4 to your computer and use it in GitHub Desktop.
Simple helper class for Mjml.
This file contains 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
<?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 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
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