Code like “if(related, related, “else”)” does not forward the “related” property faithfully, but instead shows its markdown links as raw strings.
Steps to reproduce
In an otherwise empty Sandbox Vault, create the following note (remove the escape character in the last row):
---
related:
- "[Obsidian](https://obsidian.md)"
---
```base
formulas:
ifRelated: if(related, related, "else")
views:
- type: table
name: Table
order:
- file.name
- related
- formula.ifRelated
sort:
- property: formula.ifRelated
direction: DESC
\```
Did you follow the troubleshooting guide? [Y/N]
Yes.
Expected result
The base properties “related” and “ifRelated” should have identical contents.
Actual result
The “related” property shows a proper markdown link (Obsidian), but the “ifRelated” property shows that same link as a raw text string, not a link: [Obsidian](https://obsidian.md)
Environment
SYSTEM INFO:
Obsidian version: 1.12.7
Installer version: 1.12.7
Operating system: Windows 10 Home 10.0.19045
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: on
RECOMMENDATIONS:
none
Additional information
Casting values to links via link() is not a viable solution (it just turns the string into a link to an uncreated note).
Workaround
For anyone in the same situation finding this thread via search: Resident bases help channel saint sailKite on the Obsidian Discord gave me this snippet:
if(related,
related.map(
link(
value.replace(/^\[.*?\]\((.*?)\)$/, "$1"),
value.replace(/^\[(.*?)\].*$/, "$1")
)
),
"else"
)