Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-140627] [MEP] Replace MEP placeholders when loading fragments #3193

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function replaceDotMedia(path, doc) {
}

export default async function init(a) {
const { decorateArea, mep } = getConfig();
const { decorateArea, mep, placeholders } = getConfig();
let relHref = localizeLink(a.href);
let inline = false;

Expand Down Expand Up @@ -125,13 +125,16 @@ export default async function init(a) {
}

updateFragMap(fragment, a, relHref);
if (a.dataset.manifestId || a.dataset.adobeTargetTestid) {
const { updateFragDataProps } = await import('../../features/personalization/personalization.js');
updateFragDataProps(a, inline, sections, fragment);
}
if (mep?.commands?.length) {
const { handleCommands } = await import('../../features/personalization/personalization.js');
handleCommands(mep?.commands, fragment, false, true);
if (a.dataset.manifestId
|| a.dataset.adobeTargetTestid
|| mep?.commands?.length
|| placeholders) {
const { updateFragDataProps, handleCommands, replacePlaceholders } = await import('../../features/personalization/personalization.js');
if (a.dataset.manifestId || a.dataset.adobeTargetTestid) {
updateFragDataProps(a, inline, sections, fragment);
}
if (mep?.commands?.length) handleCommands(mep?.commands, fragment, false, true);
if (placeholders) fragment.innerHTML = replacePlaceholders(fragment.innerHTML, placeholders);
}
if (inline) {
insertInlineFrag(sections, a, relHref, mep);
Expand Down
4 changes: 4 additions & 0 deletions test/blocks/fragment/fragment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config = {
contentRoot: `${window.location.origin}${getLocale(locales).prefix}`,
decorateArea,
locales,
placeholders: { placeholdercheck: 'hello world' },
mep: {
commands: [
{
Expand Down Expand Up @@ -53,6 +54,9 @@ describe('Fragments', () => {
await getFragment(a);
const h1 = document.querySelector('h1');
expect(h1).to.exist;
const p = document.querySelector('#placeholdercheck');
expect(p).to.exist;
expect(p.innerHTML).to.equal('hello world');
});

it('Loads a fragment with cache control', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/blocks/fragment/mocks/fragments/fragment.plain.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div>
<h1>Hello World</1h>
<h1>Hello World</h1>
<p id="placeholdercheck">{{placeholdercheck}}</p>
</div>
Loading