Problem: Custom Fields in Aristotle can only be text, numbers, choices or JSON structured data. There is no simple way to have a field that is just for a URL.
Feature: We are going to solve this using the Custom Fields in Aristotle
Snippets:
-
When setting up a custom field, select the Structured Data (JSON) option
-
Include the following JSON Schema.
The pattern for the URL field is a regular expression, and can be used to restrict to specific domains (see below):
{
"type": "object",
"properties": {
"url": {
"type": "string",
"pattern": "^.*://.*",
"description": "Link to the website"
},
"display_text": {
"type": "string",
"minLength": 3,
"description": "Text to be shown instead of the hyper link"
}
}
}
- Include the JSON Form to display these fields - the example below is a
VerticalLayout
(display text above URL), but changing this toHorizontalLayout
would set these side by side.
"type": "VerticalLayout",
"elements": [
{
"type": "Control",
"scope": "#/properties/display_text"
},
{
"type": "Control",
"scope": "#/properties/url"
}
]
}
- Set the View layout to render the URL as a HTML link:
<a href="{{ value.url }}">
{% if value.display_text %}
{{value.display_text}}
{% else %}
{{ value.url}}
{% endif %}
</a>
Example screenshot of the editor:
Example screenshot of the rendered URL in the item page:
Sample patterns for restricting domains:
- To restrict to a certain domain: , eg. only
help.aristotlemetadata.com
:
"pattern": "^.*://help.aristotlemetadata.com/.*",
- To restrict to any subdomain: , eg. only subomdains of
aristotlemetadata.com
, such ashelp.aristotlemetadata.com
orcommunity.aristotlemetadata.com
:
"pattern": "^.*://.*.aristotlemetadata.com$",