テンプレートをパラメータとして
MostlyRender テンプレートは、キャンバス(幅 × 高さ、背景)に名前付き レイヤーのスタックを加えたものです。重要な考え方は以下の通りです:
レイヤー名が API パラメータです。 レンダリング時にレイヤーの表示内容を変更するには、レイヤーの名前をキーとした
modificationsを送信します。
# Modifications
テキストレイヤー title、画像レイヤー photo、QR レイヤー link を含むテンプレートがある場合:
{
"template": "tpl_abc",
"modifications": {
"title": "Renders that never go dark",
"photo": "https://example.com/hero.jpg",
"link": "https://mostlyrender.com"
}
}
- テキストレイヤーの string はそのテキストを設定します。
- 画像レイヤーの string はその
srcを設定します。 - QR レイヤーの string はエンコードされた値を設定します。
- object はレイヤーにマージされるため、スタイルもオーバーライドできます:
{ "modifications": { "title": { "text": "On sale", "color": "#e11d48" } } }
記述しないレイヤーは設計時のデフォルトを保持します。未知のレイヤー名は無視されます。
# テンプレートのリスト表示
curl https://api.mostlyrender.com/v1/templates \
-H "Authorization: Bearer mr_live_…"
{
"templates": [
{ "id": "tpl_abc", "name": "Launch card", "width": 1200, "height": 630, "engine": "layers" }
]
}
id をレンダリング呼び出しの template として使用します。テンプレート(作成、編集、
削除)はアプリエディタで管理します。