Beispiel-App im gitext ablegen, dann die essentiellen Teile hier hereinkopieren.
Goal: Send a Newsletter that is based on a Mailing Template but also contains content that is dynamically gathered and rendered with CSE.
cmsbs-conf/conf.d/dynamic-newsletter-template.xml:
/// <reference path="../../../.vscode.js"/> function createEventFile(channelName, mailingTemplateId, content) { return `<event archive="true"> <destination> <channel>${channelName}</channel> </destination> <global special="content" trim="true"> ${Strings.encodeXml(content)} </global> <data> <message>${mailingTemplateId}</message> <email archiveOutgoingEmails="false" obeyPreferHtml="false" sendBothParts="false" trackingMode="Off"></email> </data> <tag>${NEWSLETTER_TAG}</tag> </event>`; } function renderOfferList(offers) { return `<ul>${offers.map(renderOffer).join('')}</ul>`; } function renderOffer(offer) { const companyPlace = []; if (offer.company) companyPlace.push(Strings.encodeXml(offer.company)); if (offer.city) companyPlace.push(Strings.encodeXml(offer.city)); return ( `<li style="margin-bottom: 8px"> <strong>${Strings.encodeXml(offer.title)}</strong><br/> ${companyPlace.join(', ')} </li>` ); } export function run() { const channelName = NEWSLETTER_LIST_NAME_PREFIX + portal; const mailingTemplateId = MAILING_TEMPLATE_ID_PREFIX + portal; const offers = JobOffer.list({ status: 'p', portal, orderBy: 'jobofferFirstPublishedAt desc', max: 35, publishedAfter: getLastSendDate() }); if (offers.length > 0) { UM.println(`Bereite Newsletter für Portal '${portal}' vor: ${offers.length} Angebote.`); const content = renderOfferList(offers); const eventFile = createEventFile(channelName, mailingTemplateId, content); UM.newsletterArchive.send(eventFile); } else { UM.println(`Keine Angebote in Portal '${portal}'.`); } }
RenderEntryCallback:
/// <reference path="../../../.vscode.js"/> RenderEntryCallback.prototype.nvRenderEncryptAgtnr = function() { const gaEntry = getBeraterForEntry(this.entry); if (gaEntry) { this.value = `agNr=${encodeURIComponent(gaEntry.get('encryptAgtnr'))}`; } else { this.value = `agNr=${encodeURIComponent(nvConfig.generalagenturen.fallback.encryptAgtnr)}`; } return true; }