igor_nadiein
4 years agoGuide
Default bio widget doen't work for plain Users and can't parse it from DB for plain Users
Hi folks. Need the help of the community brain. Found out that the default user bio widget, which parse User description from the settings doesn't work for plain Users except of Admins.
So I decided to write my own component to parse that info from DB.
Here is the code:
<#include "theme-lib.common-variables.ftl" />
<#if user.registered >
<#assign qry = "SELECT biography FROM users WHERE id = '${user.id}'"?url />
<#assign res = rest('2.0', '/search?q=${qry}') />
</#if>
<@liaAddScript>
;(function() {
const messageElement = document.querySelector('.lia-component-article');
if (!messageElement) return;
<#if user.registered>
<#if ( res.status?matches('success') && (res.data.size > 0) )>
<#assign output = res.data.items[0].biography?esc />
const selectors = {
main: '.lia-quilt-row-main',
wrapper: '.lia-quilt-column-alley-single',
ref: '#labelsForMessage',
bio: 'custom-widget-user-bios'
};
const parent = messageElement.querySelector(selectors.main + ' ' + selectors.wrapper);
const refEl = messageElement.querySelector(selectors.ref);
let p = document.createElement('p');
p.classList.add(selectors.bio);
p.textContent = '${output}';
console.log(messageElement, refEl)
parent.insertBefore(p, refEl);
</#if>
</#if>
}());
</@liaAddScript>
It Does work with Admins, but again, does not work with plain Users somewhy. It throw an exception in the console:
<div style="font-style: italic; font-weight: lighter; color: darkGrey; background-color: Beige; padding: 10px;" class="lia-widget-not-found">
This widget could not be displayed.
</div>
Help me pls, what's going wrong with that user bio widget and Data i wanna parse it to the view by myself.
Also I didn't find any flag in the admin that could representatively control that feature and enable/disable it.