# Creating a Dataview Backlinks Panel with Context

**URL:** <https://forum.obsidian.md/t/creating-a-dataview-backlinks-panel-with-context/62379>\
**Category:** Help\
**Tags:** backlinks, dataview, internal-links\
**Created:** [June 30, 2023, 3:07am UTC](https://forum.obsidian.md/t/creating-a-dataview-backlinks-panel-with-context/62379 "2023-06-30T03:07:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bluemoondragon07](https://forum.obsidian.md/user_avatar/forum.obsidian.md/bluemoondragon07/32/47805_2.png) [@Bluemoondragon07](https://forum.obsidian.md/u/Bluemoondragon07)\
**Post date:** [June 30, 2023, 3:07am UTC](https://forum.obsidian.md/t/creating-a-dataview-backlinks-panel-with-context/62379/1 "2023-06-30T03:07:30Z")

</div>

# What I’m Trying to Do

I am trying to make some Dataviewjs code that will show the backlinks and outlinks of the active note from the sidebar _ **and** _ show the context of each link. By context, what I mean is the line or sentence that the link can be found in. It would look sort of like this:

 ![Screenshot 2023-06-29 183113](https://forum.obsidian.md/uploads/default/original/3X/d/6/d6a8e2acbfbaa29cca1bd993ad693cd364fd0877.jpeg)

Except, of course, “Some description” would be replaced by the sentence the link apears in.

# What I’ve Tried

Here is the code used in the image above:

````auto
```dataviewjs

// This gets info from the active pane. 

const getFirstSplit = (split) => { if (split.type == "tabs") { return split } else if (split.type == "split") { return getFirstSplit(split.children[0]) } }
let firstSplit = getFirstSplit(app.workspace.rootSplit)
let current = firstSplit.children[firstSplit.currentTab].view.file
let page = dv.page(current.path)
  
  if (page != undefined) {
    let backlinks = page.file.inlinks
    let links = page.file.outlinks

// Got lost here...
      let content = await dv.io.load(current.path)
      let referenceText = content.match(/^[^\.!?]*(page.file.link)[^\.!?]*[\.!?]/i)

referenceText = "Some description" // demo purposes; remove later

// Backlinks Section
    if (backlinks != undefined) {
		backlinks = backlinks.map(p => p + "<br> " + referenceText)
      dv.header(1, "==" + backlinks.length + "== backlinks for *" + page.file.name + "*")
      dv.list(backlinks)
    }

// Outlinks Section
 if (links != undefined) {
		links = links.map(p => p + "<br> " + referenceText)
      dv.header(1, "==" + links.length + "== pages linked in *" + page.file.name + "*")
      dv.list(links)
    }

}
```

````

It’s based on this [Novel info panel code](https://forum.obsidian.md/t/novel-writing-info-panel-with-dataviewjs/62034) I saw earlier, so that’s where most of the code comes from, and I don’t really know what I’m doing—mostly just made this through trial and error. I feel like I’m pretty close, but now I’m stuck.

Does anyone know how I could change this so that the `referenceText` for each backlink and outlink is retrieved and displayed like above?

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [September 28, 2023, 3:07am UTC](https://forum.obsidian.md/t/creating-a-dataview-backlinks-panel-with-context/62379/2 "2023-09-28T03:07:44Z")

</div>

Closed on September 28, 2023, 3:07am UTC

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