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

Update region.js - Proposal for flags empty and raw #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions helpers/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,29 @@ const factory = globals => {
return function(params) {
let regionId = params.hash.name;
let regionTranslation = params.hash.translation;
let regionEmpty = params.hash.empty; //Propal key of empty
let regionRaw = params.hash.raw; //Propal key of raw
let contentRegions = globals.getContent();

if (!contentRegions) {
return '';
}
const translationDataAttribute = regionTranslation ? ` data-content-region-translation="${regionTranslation}"` : '';

const content = `<div data-content-region="${regionId}"${translationDataAttribute}>${contentRegions[regionId] || ''}</div>`;
// If content is empty, and flag to render nothing `empty` is set, then return nothing because there is nothing to render.
if (!contentRegions[regionId] && regionEmpty) {
return '';
}

//Write just the region content to the output variable.
//If the flag is set for raw rendering, this will be the output.
let content = contentRegions[regionId] || '';
if (!regionRaw) {
//Return the original structure that is typical of the {{region}} handlebars entity.
const translationDataAttribute = regionTranslation ? ` data-content-region-translation="${regionTranslation}"` : '';
//Original returned structure.
content = `<div data-content-region="${regionId}"${translationDataAttribute}>${contentRegions[regionId] || ''}</div>`;
}

return new globals.handlebars.SafeString(content);
};
};
Expand Down