Create wiki 'autolink' functionality

I am building a reference section for a new project, and it’s going to behave like a wiki:

Data type: Element - Name, Slug, Description

Example of a description: This element is related to #element2# and #element3# and …etc

I want to link #element2# and #element3# to their own pages (/element-details/element3)

I have the proper slugs setup but I can’t figure out how to loop through all of the occurrences matched by the RegEx. I just don’t want to deal with the hassle of creating these links manually every time I reference one of the elements.

The RegEx finds all the instances just fine, but I can’t figure out how to replace each occurrence with dynamic text. Basically, this string from the description field:

This element is related to #element2# and #element3#

should display as:

This element is related to Element2(the name of the element, and it links to /element-details/SLUG) and Element3(the name of the element, links to /element-details/SLUG)

This replaces all instances with the same text, which is expected, but I can’t access each instance of the RegEx match.

I don’t expect these to change and I guess I could just manually add these when I enter all the data, but I don’t really want to deal with broken links and massive find/replace on the database if I change things later.

1 Like