Smart links: Operator 'is in' not working?
Smart links Operator 'is in' not working as intended in Django because template.render returns a string.
In Expression I'm looking for document numbers through content and ocr_content with regex_findall tag which returns a list of matches (screenshot):
{% with document.latest_version.ocr_content|join:" " as ocr_content %}
{% with document.latest_version.content|join:" " as content %}
{% with ocr_content|add:content as joined_text %}
{% regex_findall "\b0?1+-[01458]+-\d{1,4}" joined_text as result %}
{% if result %}{{ result }}{% endif %}
{% endwith %}{% endwith %}{% endwith %}
Foreign document field: Metadata type value.
In Sandbox of test document this expression returns a list (screenshot):
['01-08-539', '01-08-570', '01-08-586', '01-08-627', '01-08-696', '01-08-539', '01-08-539', '01-08-570', '01-08-586', '01-08-627', '01-08-696', '01-08-539']
I have documents with this numbers in metadata, but none of it shows up in Smart links for test document.
To get linked documents (screenshot), i changed final part of Expression to {% if result %}{{ result|join" " }}{% endif %}
and modified (only for this test) template.render like this: template.render(context={'document': document}).split()
. This change of cource breaks any other smart links.
Workaround
- Use Operator: is in regular expression
- In Expression join result by "|" (OR operator) and add some random string that never get matches from metadata in {% else %}:
{% if result %}{{ result|join"|" }}{% else %}n0_resu1ts{% endif %}
. Without {% else %} part document with empty result list will match ALL other documents multiple times (by count of added metadata fields).