Hi everyone, I’m trying to customize mi post page, but the code that I have found don’t work anymore… And I can’t figure out why, this is the code:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
let currentPost
$w.onReady(function () {
wixLocation.onChange((location) => {
initPage()
});
initPage()
})
async function initPage() {
$w("#post1").getPost().then(async post => {
currentPost = await loadExtraPostData(post)
assignPostDataToUIElements()
}); }
async function loadExtraPostData(post) {
let postDataFromCollection = await wixData.query("Blog/Posts")
.eq("post", post._id)
.find()
postDataFromCollection = postDataFromCollection.items[0]
return mergePostData(post, postDataFromCollection)
}
async function mergePostData(post, extraData) {
return Object.assign({}, post, extraData)
}
function assignPostDataToUIElements() {
$w("#postTitle").text = currentPost.title
$w("#authorName").text = `Written by: ${currentPost.author}`
$w("#photographerName").text = `Images by: ${currentPost.photographer}`
$w("#postHeaderStrip").background.src = currentPost.coverImage
$w("#postHeaderStrip").show("fade")
}