Display Member Metadata

Article author
Duncan Hamra

This feature lets you display Member Metadata in the same way you can Displaying Member Data. If this is your first time pulling member data into your site, please first read the doc mentioned above. 

To replace headings, paragraphs, divs and span elements with dynamic metadata values, paste the following snippet before the closing BODY tag of your site. 

// paste in body of global site scripts
function replaceTextWithMetadata(metadata) {
  var els = Array.from(document.querySelectorAll('[data-ms-member-meta]'));
  els.forEach((el) => {
    const key = el.getAttribute('data-ms-member-meta');
    el.innerHTML = metadata[key];
  });
}

window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
  if(member && member.metaData) { 
		replaceTextWithMetadata(member.metaData) 
	}
});

Usage:

Add the data-ms-member-meta="your metadata key” data attribute to any div, span or text element.

data-ms-member-meta="your metadata key"

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.