Dataview : Filter incoming links to a file based on filename

Things I have tried

let links = dv.current().file.inlinks
length = links.length
for (let i = 0; i < length; i++) {  
	if (links[i].includes("🌲")){
		dv.span(link[i])
	}
}

What I’m trying to do

Render all incoming links with “:evergreen_tree:” in its filename in a single line

let links = dv.current().file.inlinks
length = links.length
for (let i = 0; i < length; i++) {  
	if (dv.contains(links[i],"🌲")){
		dv.span(link[i])
	}
}

I tried doing this also

Hi.
If a DQL list, I could help better.
In DVJS… well, without JS knowledge, I just can offer an “insecure” dvjs query:

dv.span(dv.current().file.inlinks.filter(f => f.path.includes("🌲")).join())
1 Like

Thanks a lot, your solution works perfectly :grin:. But can you explain why my code didn’t work, trying to learn how this plugin works

Are you asking me to explain js? :slight_smile:
I can’t do that because my knowledge in JS is zero.
I read your code and understand some steps, but in a very basic way (for example: I don’t know how “let”, “for”, “const” works; I don’t understand why you need the length; I don’t understand for (let i = 0; i < length; i++; …). But I deduced your goal.
This is an insecure statement, but maybe your code have a problem with the fact that file.inlinks is by default an array and you try to verify a condition in “link” as if the link is a string…
But this is guessing…
Sorry but I can’t explain more (because it’s js stuff)

I tried doing this myself, but couldn’t. How will you create a list of incoming links to file excluding :evergreen_tree: in filemane. Thanks again

The inverse? in dvjs or dql?
Taking the previous query, I think you just need to add a “!” before the filter condition, i.e., the “negation” of that condition:

dv.span(dv.current().file.inlinks.filter(f => !f.path.includes("🌲")).join())
1 Like

How will you make it a list

DQL

```dataview
LIST
FROM [[]]
WHERE !contains(file.name, "🌲")
```

DVJS

```dataviewjs
dv.list(dv.current().file.inlinks.filter(f => !f.path.includes("🌲")))
```
2 Likes

What if I try to filter two terms :evergreen_tree: and “IW”, I tried doing this

dv.list(dv.current().file.inlinks.filter(f => !f.path.includes("🌲") and !f.path.includes("IW")) 
dv.list(dv.current().file.inlinks.filter(f => !f.path.includes("🌲") && !f.path.includes("IW")))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.