High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
{{ define "admin-template" -}}
{{ template "admin-header" . }}
{{- $crumbTitle := .L.T "templates.newTemplate" -}}
{{- if not .Data.IsNew }}{{ $crumbTitle = .Data.Template.Name }}{{ end -}}
{{ template "breadcrumbs" dict "Root" . "Current" $crumbTitle "Parents" (list (dict "Label" (.L.T "globals.terms.campaigns") "URL" (URI "/admin/campaigns") "CanLink" (.Data.Can "campaigns:get" "campaigns:get_all")) (dict "Label" (.L.T "globals.terms.templates") "URL" (URI "/admin/templates") "CanLink" (.Data.Can "templates:get"))) }}
{{- $d := .Data -}}
{{- $t := $d.Template -}}
{{- $isNew := $d.IsNew -}}
{{- $canManage := $d.Can "templates:manage" -}}
<script>
const _tpl = {{ ToJSON $t }};
</script>
<section class="templates" x-data="templateForm(_tpl, {{ $isNew }})"
@keydown.ctrl.s.window.prevent="onSaveShortcut" @keydown.meta.s.window.prevent="onSaveShortcut"
@keydown.window.prevent.f9="onPreviewBody">
<header class="row page-header">
<div class="col-6">
<div class="hstack gap-1">
<div class="avatar avatar-title">
{{- if not $isNew }}
{{- $kind := "campaign-template" -}}
{{- if eq $t.Type "tx" }}{{ $kind = "tx-template" }}{{ else if eq $t.Type "campaign_visual" }}{{ $kind = "campaign-visual-template" }}{{ end -}}
{{ template "avatar-icon" dict "Kind" $kind "Name" $t.Name "Href" (printf "%s/%d" (URI "/admin/templates") $t.ID) "Title" (printf "%s %s" ($.L.T "globals.buttons.view") $t.Name) }}
{{- end }}
<h1 class="page-title avatar-label">
{{- if $isNew }}{{ .L.T "templates.newTemplate" }}{{ else }}{{ $t.Name }}{{ end -}}
</h1>
</div>
{{- if and (not $isNew) $t.IsDefault }}{{ Badge (.L.T "globals.terms.default") "enum" }}{{ end }}
</div>
</div>
<div class="col-6 hstack justify-end buttons">
<button type="button" class="outline external" data-testid="btn-preview" @click="onPreviewBody" aria-keyshortcuts="F9">{{ Icon "eye" }} {{ .L.T "globals.buttons.preview" }}</button>
</div>
</header>
<form @submit.prevent="onSubmit">
<div class="page-content content">
<fieldset class="card">
<legend>{{ .L.Tc "globals.terms.template" 1 }}</legend>
<div class="row">
<div class="col-9">
<label data-field>
{{ .L.T "globals.fields.name" }}
<input name="name" maxlength="200" autofocus required x-model="form.name" placeholder="{{ .L.T "globals.fields.name" }}" />
</label>
</div>
<div class="col-3">
<label data-field>
{{ .L.T "globals.fields.type" }}
<select name="type" x-model="form.type" {{ if not $isNew }}disabled{{ end }}>
<option value="campaign">{{ .L.Tc "templates.typeCampaignHTML" 1 }}</option>
<option value="campaign_visual">{{ .L.Tc "templates.typeCampaignVisual" 1 }}</option>
<option value="tx">{{ .L.Tc "templates.typeTransactional" 1 }}</option>
</select>
</label>
</div>
</div>
<template x-if="form.type === 'tx'">
<label data-field>
{{ .L.T "globals.fields.subject" }}
<input name="subject" maxlength="200" x-model="form.subject" placeholder="{{ .L.T "globals.fields.subject" }}" />
</label>
</template>
</fieldset>
<fieldset class="card">
<legend>{{ .L.T "globals.fields.content" }}</legend>
<div class="editor-body">
<template x-if="form.type === 'campaign_visual'">
<visual-editor base="{{ URI "/admin/static/email-builder" }}" @editor-change="form.body = $event.detail.body; form.body_source = $event.detail.source"><textarea>{{ $t.BodySource.String }}</textarea></visual-editor>
</template>
<template x-if="form.type !== 'campaign_visual'">
<code-editor lang="html" @input="form.body = $event.target.value"><textarea>{{ $t.Body }}</textarea></code-editor>
</template>
</div>
<p class="text-light mt-2">
<template x-if="form.type === 'campaign'">
<span>{{ .L.Ts "templates.placeholderHelp" "placeholder" "{{ template \"content\" . }}" }}</span>
</template>
<a href="https://listmonk.app/docs/templating" target="_blank" rel="noopener noreferrer">{{ Icon "link-2" }} {{ .L.T "globals.buttons.learnMore" }}</a>
</p>
</fieldset>
<footer class="hstack justify-between mt-6">
<div class="hstack gap-1">
{{- if not $isNew }}
<button type="button" class="small" data-variant="secondary" title="{{ .L.T "globals.messages.clickToCopy" }}" aria-label="{{ .L.T "globals.fields.id" }}" @click="copyToClipboard(form.id)">
<strong>{{ .L.T "globals.fields.id" }}</strong> <span x-text="form.id"></span>
</button>
{{- end }}
</div>
<div class="hstack gap-3 justify-end">
{{- if $canManage }}
<button type="submit" data-variant="primary" data-testid="btn-save" :disabled="isLoading('templates')" :aria-busy="isLoading('templates')">{{ Icon "save" }} {{ .L.T "globals.buttons.save" }}</button>
{{- end }}
</div>
</footer>
</div>
</form>
{{ template "template-preview" . }}
</section>
<script type="module" src="{{ URI "/admin/static/js/views/templates.js" }}?v={{ .AssetVersion }}" defer></script>
<script type="module" src="{{ URI "/admin/static/js/code-editor.js" }}?v={{ .AssetVersion }}" defer></script>
<script type="module" src="{{ URI "/admin/static/js/visual-editor.js" }}?v={{ .AssetVersion }}" defer></script>
{{ template "admin-footer" . -}}
{{ end }}