Show meta data tag values in a topic

This forum is for all Flare issues not related to any of the other categories.
Post Reply
jgary
Jr. Propeller Head
Posts: 3
Joined: Thu Sep 01, 2022 2:49 pm

Show meta data tag values in a topic

Post 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.
NorthEast
Master Propellus Maximus
Posts: 6365
Joined: Mon Mar 05, 2007 8:33 am

Re: Show meta data tag values in a topic

Post 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>
jgary
Jr. Propeller Head
Posts: 3
Joined: Thu Sep 01, 2022 2:49 pm

Re: Show meta data tag values in a topic

Post by jgary »

Thank you so much. This is exactly what I was looking for and it worked great!
jgary
Jr. Propeller Head
Posts: 3
Joined: Thu Sep 01, 2022 2:49 pm

Re: Show meta data tag values in a topic

Post 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
NorthEast
Master Propellus Maximus
Posts: 6365
Joined: Mon Mar 05, 2007 8:33 am

Re: Show meta data tag values in a topic

Post 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>
Post Reply