2016-08-04 13 views
0

私はMarketoの電子メール2.0アプリケーション用の電子メールテンプレートを作成しています。これらのテンプレートは変数宣言を利用します。 これらはメタ値として参照され、テンプレートに基づいて電子メールを生成するときに編集可能です。可変メタリファレンスには以下のものがあります。文字列、ブール値、色、数字など変数をメタ値で置き換えるためのGulpプラグイン

変数を宣言するための構文は次のとおりです。

<meta class="mktoNumber" id="articleSectionSpacerBottom" mktoname="Article heading spacer bottom" default="30" min="0" max="30" step="5"> 

変数は、次のように文書の本文に呼ばれている:私は「

${articleSpacerBottom} 

各変数のデフォルト値を処理できるプラグインを見つけたいので、電子メールテンプレートをローカルにテストできます。

したがって、変数の各インスタンスまたは各インスタンスに対して、関連するメタタグを見つけてデフォルト値を取得します。

これをhtml処理タスクに追加して、injectsPartialsプラグインの直後に実行したいと考えています。

gulp.task('html', function() { 
    gulp.src(source + '*.+(html|php)') 
    .pipe($.plumber()) 
    .pipe($.injectPartials({ 
     removeTags: true 
    })) 
    .pipe($.inline({ 
     base: source, 
     css: $.cleanCss, 
     disabledTypes: ['svg', 'img'] 
    })) 
    .pipe($.inlineCss({ 
     applyStyleTags: true, 
     applyLinkTags: true, 
     removeStyleTags: false, 
     removeLinkTags: true, 
     applyWidthAttributes: true, 
     applyTableAttributes: true 
    })) 
    .pipe($.replace('src="images/', 'src="' + mtkosrc + template +'-')) 
    .pipe($.replace('mktoname', 'mktoName')) 
    .pipe(gulp.dest(build)) 
    .pipe(reload({ 
     stream: true 
    })); 
}); 

答えて

0

私は、あなたが望むことをするすぐに使えるプラグインはないと思っています。あなた自身で何かを書く必要があります。

しかしこれはあまりにも厳しくはありません。 map-streamを使用すると、ストリーム内の各ファイルvinylにアクセスできます。その後、cheerioを使用してHTMLを解析し、<meta>というタグを見つけます。その後、その簡単な検索&が操作を置き換えます。

ここで私の作品小さな例です:

gulpfile.js

var gulp = require('gulp'); 
var cheerio = require('cheerio'); 
var map = require('map-stream'); 

gulp.task('default', function() { 
    gulp.src('index.html') 
    .pipe(map(function(file, done) { 
     var html = file.contents.toString(); 
     var $$ = cheerio.load(html); 
     $$('meta').each(function() { 
     var meta = $$(this); 
     var variable = new RegExp('\\$\\{' + meta.attr('id') + '\\}', 'g'); 
     html = html.replace(variable, meta.attr('default')); 
     }); 
     file.contents = new Buffer(html); 
     done(null, file); 
    })) 
    .pipe(gulp.dest('build')); 
}); 

index.htmlを

<html> 
<head> 
<meta class="mktoNumber" id="articleSectionSpacerBottom1" mktoname="Article heading spacer bottom" default="30" min="0" max="30" step="5"> 
<meta class="mktoNumber" id="articleSectionSpacerBottom2" mktoname="Article heading spacer bottom" default="42" min="0" max="30" step="5"> 
</head> 
<body> 
${articleSectionSpacerBottom1} 
${articleSectionSpacerBottom2} 
</body> 
</html> 

ビルド/ index.htmlを

<html> 
<head> 
<meta class="mktoNumber" id="articleSectionSpacerBottom1" mktoname="Article heading spacer bottom" default="30" min="0" max="30" step="5"> 
<meta class="mktoNumber" id="articleSectionSpacerBottom2" mktoname="Article heading spacer bottom" default="42" min="0" max="30" step="5"> 
</head> 
<body> 
30 
42 
</body> 
</html> 
+0

うわー、ありがとうございました。どこから始めたらいいか分からなかった。それは魅力のように働く。 – onebitrocket

関連する問題