Metadata fields in CONTENTdm do not support arbitrary styling or formatting. There are certain conditions where metadata is automatically formatted (URLs, Controlled Vocabularies) but beyond that metadata will be displayed as plain text in the CONTENTdm website. This recipe provides a method to create hyperlinks with custom display text within metadata fields. The script relies on specific formatting in metadata fields and will dynamically reformat the metadata into hyperlinks.
To use this recipe, you will need to choose one of the metadata formats (described below) and identify the nickname of the field to be reformatted. You then use these two values to specify where the script should execute. Edit the reformatField( ... ); lines down near the bottom of the script to use the nickname of the field you wish to format and the delimiter you want to use. For example, if you want links with custom display text in a field with the nickname "source" and you have chosen to use the markdown format, you will run the script like this:
reformatField('source','markdown');
If you have multiple fields to reformat, you can run the script multiple times, e.g.:
reformatField('source','markdown'); reformatField('creato','markdown');
You would enter these twice in the ready and update events in the JavaScript file.
After altering these lines, re-save the file to the same name making sure to retain the .js extension. Upload it via the preferred Website Config Tool > Custom > Custom Pages tab, then Publish the changes.
There are three different metadata format rules supported by this recipe. The metadata must be entered in one of these ways:
Desired display text, followed by a colon (:), followed by the URL for the hyperlink. Use <br> as a delimiter for multiple links in the same field.
Click here for link 1: https://example.com<br>Click here for link 2: https://example.com<br>
Click here for link 1
Click here for link 2
Desired display text, followed by a vertical pipe (|), followed by the URL for the hyperlink. Use a semicolon (;) as a delimiter for multiple links in the same field.
Click here for link 1 | https://example.com; Click here for link 2 | https://example.com
Click here for link 1
Click here for link 2
Desired display text in square brackets, followed by the URL for hyperlink in parentheses. Use a semicolon (;) as a delimiter for multiple links in the same field.
[Click here for link 1](https://example.com); [Click here for link 2](https://example.com)
Click here for link 1
Click here for link 2