Page 1 of 1

Show meta data tag values in a topic

Posted: Fri Mar 22, 2024 4:29 pm
by jgary
Is there a way to show meta data in a topic? I've created a List type Meta tag to designate topics for different audiences (Administrator, User). After selecting the value in the topic Properties > Meta Tags tab, I can see the meta data when I View Page Source for the output, but I would like to also show the user type from the meta data within the actual topic. I don't see a way to do this in Flare, but I'm hoping someone has an idea of how we can programmatically do that.

I know that's not specifically what meta data is intended for, but it would be really helpful for our purposes.

Re: Show meta data tag values in a topic

Posted: Mon Mar 25, 2024 12:51 am
by NorthEast
You can use a script to do this.

This is a meta tag in the head section:

Code: Select all

<meta name="description" content="hello" />
In the topic body, use an ID to mark where to insert the text fropm the meta tag - in this case, ID="meta-description".

Code: Select all

<p>Meta description is: <span id="meta-description"></span></p>
Then after this in the topic body, add this script - this looks for the meta tag (name='description') and gets the tag's "content" attribute, then displays this as text in the tag with the ID:

Code: Select all

<script type="text/javascript">/*<![CDATA[*/$( document ).ready(function() {
	var metaDescription = $("meta[name='description']").attr("content");
	$("#meta-description").text(metaDescription);
});/*]]>*/</script>

Re: Show meta data tag values in a topic

Posted: Mon Mar 25, 2024 10:46 am
by jgary
Thank you so much. This is exactly what I was looking for and it worked great!

Re: Show meta data tag values in a topic

Posted: Thu Apr 11, 2024 3:52 pm
by jgary
Again, your suggestion was super helpful! The script works great, however my file has multiple values for the meta tag. The output shows the list of values, separated by commas, but without any spaces.
For example:
Products: Product A,Product B,Product C,Product E

Do you know how I can modify the script to show:
Products: Product A, Product B, Product C, Product E

Re: Show meta data tag values in a topic

Posted: Sun Apr 21, 2024 11:45 pm
by NorthEast
You could use replaceAll to replace the comma "," with a comma and space ", ".

Code: Select all

<script type="text/javascript">/*<![CDATA[*/$( document ).ready(function() {
	var metaDescription = $("meta[name='description']").attr("content");
	metaDescription = metaDescription.replaceAll(",", ", ");
	$("#meta-description").text(metaDescription);
});/*]]>*/</script>