# Trying to retrieve Callout with DataView

**URL:** <https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312>\
**Category:** Help\
**Created:** [July 14, 2022, 1:15am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312 "2022-07-14T01:15:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheGeneralist](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@TheGeneralist](https://forum.obsidian.md/u/TheGeneralist)\
**Post date:** [July 14, 2022, 1:15am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/1 "2022-07-14T01:15:35Z")

</div>

I tried to see any examples on the internet or the documentation on DataView Plugin, but didn’t found any resource.

I’m willing to query specific type of callouts for my weekly routine.

Any guidance to to do that would help.

Thanks!

---

<div class="post-metadata">

**Author:** ![scholarInTraining](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@scholarInTraining](https://forum.obsidian.md/u/scholarInTraining)\
**Post date:** [July 14, 2022, 4:20am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/2 "2022-07-14T04:20:09Z")

</div>

Could you describe a bit more what you are trying to do? Do you want to display the entire callout? A copy of it? Some pieces from it?

dataview looks for field names & values in your note, not arbitrary strings pf text like a callout name. The built-in Obsodian search can do text strings though! Could using the built-in Obsidian search for the name of the call-out work? (You can make search `query` blocks like dataview blocks.)  
Another alternative: Could embedding the callout work?

---

<div class="post-metadata">

**Author:** ![TheGeneralist](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/t/ecccb3/32.png) [@TheGeneralist](https://forum.obsidian.md/u/TheGeneralist)\
**Post date:** [July 14, 2022, 10:40am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/3 "2022-07-14T10:40:24Z")

</div>

I want to do simple query to get a lists of all the “questions/achievements/failure…” that I had in particular week.

Can you elaborate what do mean when " embedding the callout work?"

The search is nice, but I didn’t found a way to show the whole text of the callouts, nor a way to add time block. Is there to way to perform that?

---

<div class="post-metadata">

**Author:** ![arma](https://forum.obsidian.md/user_avatar/forum.obsidian.md/arma/32/31088_2.png) [@arma](https://forum.obsidian.md/u/arma)\
**Post date:** [August 26, 2022, 8:54am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/4 "2022-08-26T08:54:08Z")

</div>

I have the same idea / demand: the different callout types should be actionable / retrievable like additional task types.  
Checklist allows different task lists by tagging, but callout type is already like an implicit “tag”.

---

<div class="post-metadata">

**Author:** ![pljvp](https://forum.obsidian.md/user_avatar/forum.obsidian.md/pljvp/32/34707_2.png) [@pljvp](https://forum.obsidian.md/u/pljvp)\
**Post date:** [September 19, 2022, 9:19am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/5 "2022-09-19T09:19:02Z")

</div>

I am to looking for a way to show specific callouts or admontions (like question, failure) and list and group similar callouts/adminitions in a separate ‘output-card’:

**List of MyDangers:**

- some danger, link to card
- some other danger, link to card
- …

Where ‘dangers’ can be triggered from cards using admonitions like this:

```ad-danger  
some danger  
```

OR by cards using callouts like this:

\> [!DANGER]  
\> some other danger

I’m trying to accomplish this with Dataview. Unfortunately “```ad-failure” so far 😉  
Any ideas?

---

<div class="post-metadata">

**Author:** ![AlanG](https://forum.obsidian.md/user_avatar/forum.obsidian.md/alang/32/55225_2.png) [@AlanG](https://forum.obsidian.md/u/AlanG)\
**Post date:** [September 19, 2022, 9:36am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/6 "2022-09-19T09:36:15Z")

</div>

You can use the method here to extract the list of achievements etc from your callouts:

> [@Summarize Daily Notes Using Dataview](https://forum.obsidian.md/t/summarize-daily-notes-using-dataview/18049/9):
>
> You can extract the full “What happened today?” section via regex. For best performance you’ll want to change the Dataview query dv.pages() to limit it to your daily notes only. If you use the tag “#daily”, that would be dv.pages('#daily') ```dataviewjs const header = '## What happened today\\?' // You can update this to filter as you like - filtering for just your daily notes would be good const pages = dv.pages() // This regex will return text from the Summary header, until it reaches // …

You’ll need to change the regex to match what you’re looking for, but the method is the same.

---

<div class="post-metadata">

**Author:** ![pljvp](https://forum.obsidian.md/user_avatar/forum.obsidian.md/pljvp/32/34707_2.png) [@pljvp](https://forum.obsidian.md/u/pljvp)\
**Post date:** [September 19, 2022, 12:23pm UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/8 "2022-09-19T12:23:31Z")

</div>

Thank you for reaching out. I (yet) don’t understand how this works if I have more than one admonition/callout in a card and multiple bullets, for instance:

 ``` ad-abstract  
 title: atomic summary  
 \* understanding how to query  
 \* another bullet  
 ```  
 ``` ad-danger  
 title: main challenge(s)  
 \* some danger  
 \* some other danger  
 ```

1. First things first. For testing I have added this into a card ‘exploring list with dataview’:  
## Gratitude  
## what happend today?  
## here’s what happened  
## here’s what also happened

2. Also for testing, I’ve added an ‘else’:

Now I indeed get a list of all my card-titles & ‘some text’.  
Unfortunately the card ‘exploring list with dataview’ - containing the \ ## here’s what happened - doesn’t show \ ## here’s what happened.

Any thoughts, before I will tweak the regex-function for listing the \<li\>'s under “ad-danger” and/or [!DANGER]… ??

---

<div class="post-metadata">

**Author:** ![AlanG](https://forum.obsidian.md/user_avatar/forum.obsidian.md/alang/32/55225_2.png) [@AlanG](https://forum.obsidian.md/u/AlanG)\
**Post date:** [September 19, 2022, 1:28pm UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/9 "2022-09-19T13:28:42Z")

</div>

Here’s a working demo using your specific example:

[Dataview code and downloadable demo vault](https://share.note.sx/1f2nsian)

 ![image](https://forum.obsidian.md/uploads/default/original/3X/7/5/75334e0789c6573304c586a074c5de1327dc4be1.png)

---

<div class="post-metadata">

**Author:** ![pljvp](https://forum.obsidian.md/user_avatar/forum.obsidian.md/pljvp/32/34707_2.png) [@pljvp](https://forum.obsidian.md/u/pljvp)\
**Post date:** [September 19, 2022, 2:17pm UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/10 "2022-09-19T14:17:12Z")

</div>

Like a charm!  
I replace (\w+) with the type of admonition, to list these per type.  
I.T.H.A.N.K.Y.O.U. for the teaching.

---

<div class="post-metadata">

**Author:** ![dracozny](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/d/779978/32.png) [@dracozny](https://forum.obsidian.md/u/dracozny)\
**Post date:** [September 28, 2022, 8:59pm UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/11 "2022-09-28T20:59:09Z")

</div>

Is there a way to make this pull multiple admonitions from the same note? right now it only pulls the first one found.  
side Note: It also hates nested admonitions but I don’t currently have a need for those.

---

<div class="post-metadata">

**Author:** ![AlanG](https://forum.obsidian.md/user_avatar/forum.obsidian.md/alang/32/55225_2.png) [@AlanG](https://forum.obsidian.md/u/AlanG)\
**Post date:** [September 29, 2022, 6:41am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/12 "2022-09-29T06:41:08Z")

</div>

> [@dracozny](#):
>
> Is there a way to make this pull multiple admonitions from the same note? right now it only pulls the first one found.

Sure, just change the first regex to be a global regex (`'g'`), and then loop through the results.

Demo vault updated: [https://drive.google.com/file/d/1HvWT\_WlxVRVTlJw-T2CCnyPfJRNi\_kQJ/view?usp=sharing](https://drive.google.com/file/d/1HvWT_WlxVRVTlJw-T2CCnyPfJRNi_kQJ/view?usp=sharing)

````auto
```dataviewjs
// You can update this to filter as you like - filtering for just your daily notes would be good
const pages = dv.pages('#daily')
  
// This regex will find the contents of a specifically formatted callout
const regex = /\n```ad-(\w+)\r?\ntitle:(.+?)\r?\n(\*.+?)```/
  
const rows = []
for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    // Extract the summary via regex
    for (const callout of contents.match(new RegExp(regex, 'sg')) || []) {
        const match = callout.match(new RegExp(regex, 's')) 
        rows.push([match[2], match[1], match[3], page.file.link])
    }
}
  
dv.table(['Title', 'Type', 'Bullets', 'Link'], rows)
```

````

---

<div class="post-metadata">

**Author:** ![vorpal](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/v/aca169/32.png) [@vorpal](https://forum.obsidian.md/u/vorpal)\
**Post date:** [November 8, 2022, 1:02am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/13 "2022-11-08T01:02:23Z")

</div>

> [@AlanG](#):
>
> ````auto
> ```dataviewjs
> // You can update this to filter as you like - filtering for just your daily notes would be good
> const pages = dv.pages('#daily')
> 
> // This regex will find the contents of a specifically formatted callout
> const regex = /\n```ad-(\w+)\r?\ntitle:(.+?)\r?\n(\*.+?)```/
> 
> const rows = []
> for (const page of pages) {
> const file = app.vault.getAbstractFileByPath(page.file.path)
> // Read the file contents
> const contents = await app.vault.read(file)
> // Extract the summary via regex
> for (const callout of contents.match(new RegExp(regex, 'sg'))) {
> const match = callout.match(new RegExp(regex, 's')) 
> rows.push([match[2], match[1], match[3], page.file.link])
> }
> }
> 
> dv.table(['Title', 'Type', 'Bullets', 'Link'], rows)
> 
> ````
> 
> ```auto
> 
> ```

This works find for me if `dv.pages()` doesn’t return any pages (ie. dataview returns an empty table), but as soon as I use either

```auto
const pages = dv.pages()

```

or

```auto
const pages = dv.pages('#someExistingTag')

```

I get:

```auto
Evaluation Error: TypeError: contents.match is not a function or its return value is not iterable
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:15:36)
    at async DataviewJSRenderer.render (plugin:dataview:19705:13)

```

I’ve tried googling the error, but haven’t found any dataview/obsidian specific information. Is there a way to easily display the value of `pages`? I tried `dv.paragraph(pages)` but that just error-ed.

---

<div class="post-metadata">

**Author:** ![AlanG](https://forum.obsidian.md/user_avatar/forum.obsidian.md/alang/32/55225_2.png) [@AlanG](https://forum.obsidian.md/u/AlanG)\
**Post date:** [November 8, 2022, 7:13am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/14 "2022-11-08T07:13:09Z")

</div>

> [@vorpal](#):
>
> This works find for me if `dv.pages()` doesn’t return any pages (ie. dataview returns an empty table), but as soon as

First question, did you test using the demo vault in my post? If you download the demo vault and make no changes, does it function correctly?

---

<div class="post-metadata">

**Author:** ![vorpal](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/v/aca169/32.png) [@vorpal](https://forum.obsidian.md/u/vorpal)\
**Post date:** [November 8, 2022, 11:25pm UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/15 "2022-11-08T23:25:11Z")

</div>

No, I hadn’t tried the test vault because I am a bad person.

The test vault works. However it is also that case that, if I modify the test vault to be `const pages = dv.pages()` it gives the same error about `contents.match`. So there is still an issue there.

However the test vault does work fine with existing tags defined in both the YAML and the main text (so there is clearly something additional going on in my real vault).

As penance for my sins I offer a regex for anyone else who might be looking for it to catch callouts using the new syntax:

```auto
> [!NAME] title
> body

```

```auto
const regex = />\s\[\!NAME\]\s(.+?)((\n>\s.*?)*)\n/

```

Where you replace NAME with whatever the type of callout you are trying to collate (eg. INFO, NOTE, etc).

The whole script then becomes:

````nohighlight
// You can update this to filter as you like - filtering for just your daily notes would be good
const pages = dv.pages('#daily')

// This regex will find the contents of a specifically formatted callout
// const regex = /\n```ad-(\w+)\r?\ntitle:(.+?)\r?\n(\*.+?)```/
const regex = />\s\[\!NAME\]\s(.+?)((\n>\s.*?)*)\n/

const rows = []
for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    // Extract the summary via regex
    for (const callout of contents.match(new RegExp(regex, 'sg'))) {
	    const match = callout.match(new RegExp(regex, 's')) 
	    rows.push([match[1], match[2], page.file.link])
    }
}

dv.table(['Term', 'Definition', 'Link'], rows)

````

---

<div class="post-metadata">

**Author:** ![vorpal](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/v/aca169/32.png) [@vorpal](https://forum.obsidian.md/u/vorpal)\
**Post date:** [November 9, 2022, 12:21am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/16 "2022-11-09T00:21:45Z")

</div>

Having played around some more. The script fails if `dv.pages()` returns one or more pages where the regex does not match anything and so `content.match`’s  
“return value is not iterable” (as the error says). My very limited js is probably not up to working out how to fix the for loop so this doesn’t raise an error.

---

<div class="post-metadata">

**Author:** ![AlanG](https://forum.obsidian.md/user_avatar/forum.obsidian.md/alang/32/55225_2.png) [@AlanG](https://forum.obsidian.md/u/AlanG)\
**Post date:** [November 9, 2022, 12:43am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/17 "2022-11-09T00:43:46Z")

</div>

Sorry, that’s my mistake in the original code.

Just change the `contents.match` line to be:

```auto
for (const callout of contents.match(new RegExp(regex, 'sg')) || []) {

```

and that will solve the issue 🙂

It’s saying:

“Loop through the items in `contents.match`, and if that isn’t an array then loop through this empty array `[]`.”

---

<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:** [February 7, 2023, 12:43am UTC](https://forum.obsidian.md/t/trying-to-retrieve-callout-with-dataview/40312/18 "2023-02-07T00:43:47Z")

</div>

Closed on February 7, 2023, 12:43am UTC

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