fix: don't render empty widgets

This commit is contained in:
Barış Soner Uşaklı
2023-01-19 22:01:56 -05:00
parent 96922aadc2
commit 0c3b8904b8
2 changed files with 6 additions and 5 deletions

View File

@@ -9,17 +9,18 @@ module.exports.render = function (template) {
locations.forEach(function (location) {
let area = $('#content [widget-area="' + location + '"],#content [data-widget-area="' + location + '"]').eq(0);
if (area.length) {
const widgetsAtLocation = ajaxify.data.widgets[location] || [];
if (area.length || !widgetsAtLocation.length) {
return;
}
const widgetsAtLocation = ajaxify.data.widgets[location] || [];
let html = '';
widgetsAtLocation.forEach(function (widget) {
html += widget.html;
});
if (!html) {
return;
}
if (location === 'footer' && !$('#content [widget-area="footer"],#content [data-widget-area="footer"]').length) {
$('#content').append($('<div class="row"><div data-widget-area="footer" class="col-12"></div></div>'));
} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"],#content [data-widget-area="sidebar"]').length) {

View File

@@ -27,7 +27,7 @@ widgets.render = async function (uid, options) {
const returnData = {};
locations.forEach((location, i) => {
if (Array.isArray(widgetData[i]) && widgetData[i].length) {
returnData[location] = widgetData[i].filter(Boolean);
returnData[location] = widgetData[i].filter(widget => widget && widget.html);
}
});