Bases filter `contains(link(this.file.name))` also shows non link values

What I’m trying to do

I only want to show tasks in my dynamic base embedded in a project note that have a frontmatter link to the project I’m viewing. If it’s not linked, it shall not show.

In the setup below both Task 1 and Task 2 show in Project 1, although only Task 1 has a link to Project 1.

Things I have tried

This is my setup:

Tasks.base

views:
  - type: table
    name: Table
    filters:
      and:
        - project.contains(link(this.file.name))

Task 1.md

---
project:
  - "[[Project 1]]"
---

Task 2.md

---
project:
  - Project 1
---

Project 1.md

![[Tasks.base]]

BTW: Do we have a way to see what is rendered in link(this.file.name), e.g. via console?

I think you could try, as a filter :blush: :

project.contains(this)

or

project.contains(this.file)

this/this.file representing the file object the base is embedded in, it should discard the non-link/string values in the project key (I think :sweat_smile: )

You could also have something like:

project.filter(value.isType("link")).contains(this)

or

project.filter(value.isType("link") && value == this)

… if you want to “test” the type of the values stored within the project key and discard the ones you don’t need :blush:

I generally use a formula property when I want to test/render something (formula/filter) :blush: … as I don’t think you can console.log() formula results :smile:

@Pch

Thanks! All of your options work in my test vault!

In my actual working vault I ran into an issue with an error "Failed to evaluate filter: Type error in "contains", parameter "value". Expected String not, given File.

This happens when you change from property type text to list and still have text entries like:

project: "[[Project 1]]"

instead of list type:

project: 
  - "[[Project 1]]"

For a text type of key, in which you can only store either a link to project file or a simple string bearing the name of the project, I guess you could use, as a filter :

project == this

or

project == this.file

or

project.isType("link") && project == this.file.basename

… and some other variations also seems to work in my quick tests :smile:

1 Like

Various forms of property notes:

task1-list-and-link-form

---
tags:
  - test
project:
  - "[[projectXYZ]]"
---

task2-list-form

---
tags:
  - test
project:
  - projectXYZ
---

task3-text-form

---
tags:
  - test
project: projectXYZ
---

Below are the bases in a note called projectXYZ displaying all tasks depending on the type and form of property:

filters:
  and:
    - or:
        - note.project.isType("list") && note.project.contains(link(this.file))
        - note.project.isType("list") && note.project.contains(this.file.name)          
        - note.project.isType("string") && file(note.project).toString().contains(this.file.toString())      
views:
  - type: table
    name: Table
    order:
      - file.name
      - project
  1. The first form is recommended.
  2. The second is a transitional form for when you’re already using lists but not yet using links.
  3. The third is for older notes.

Why added in a group or nested?
To add any additional conditions at a higher level.

1 Like