Links to the headers generated by dv.header()

Things I have tried

Within “alphabet.md”, I generated the headers by

for (var j=0; j < 26 ; j++) {
   let alphabet = String.fromCharCode(97 + j);
   dv.header(3, alphabet);
}

What I’m trying to do

I’m trying to make links to the headers generated the above dv code.

It looks like that something like [[alphabet#a]] doesn’t work.

I’d like to know if there is any way to make links to the dv.headers.

I am not sure that there is. All codeblocks including dataview are rendered with different logic than the rest of the Obsidian document.

Thank you for your comment.

If there isn’t at this moment, I hope it can be possible sometime later.

Topic: The file.lists by example

The file.lists by example - Chapter 5: using DQL to gather list items or task items under the specific heading (and filter by L.text)(and filter by L.task or !L.task)(and filter by L.tags or L.outlinks) without the desired structure and shorten the display name of the L.header (and group by L.header)(and group by file.link)

Summary
  • How to gather list items or task items under the specific heading without the desired structure?
    • DQL10:
      • GROUP BY L.header AS G_L_header
      • To shorten the display name of the L.header
    • DQL20:
      • GROUP BY L.header AS G_L_header, GROUP BY rows.file.link AS G_fLink
      • To shorten the display name of the L.header
    • DQL30:
      • GROUP BY L.header AS G_L_header, GROUP BY "### " + rows.file.link[0] AS G_fLink
      • To shorten the display name of the L.header
      • The DQL30 is very similar to the DVJS10 with Another Example13B in the following topic.
        - Solutions: by Justdoitcc
      • The DQL30 displays one list item(or one task item) where L.text matches the WHERE contains(L.text, "1") OR contains(L.text, "2") expression. However, the DVJS10 in the topic (Chapter 4) displays one root list item(or one root task item) with its children.
  • How to create the links to the headings?(DVJS10)

Test

Summary
  • dataview: v0.5.46

Input

Summary

dictionary files

  • Location: “100_Project/01_dataviewjs/01_by_example/Q88_header/Q88_test_data”

folder: 03

  • filename : dic_19950301
---
Date: 1995-03-01
---


### input_data
#### a
- a1
- a2

#### b
- b1
- b2

#### c
- [x] c1
- [ ] c2

#### d
- [ ] d1
- [x] d2

#### e
- [!] e1
- [ ] e2

#### f



folder: 04

  • filename : dic_19950401
---
Date: 1995-04-01
---


### input_data
#### a
- a1
- a2

#### b
- b1
- b2

#### c
- [>] c1
- [ ] c2

#### d
- [x] d1
- [ ] d2

#### e
- [ ] e1
- [x] e2

#### f



DQL10_get_unique_links_of_headings_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_get_unique_links
_of_headings
_and_TABLE
file.lists yes 1.To flatten file.lists
2.To gather the links of the headers where each of the headings contains at least one list item or one task item
3.To filter by L.text
4.To group by L.header and let G_L_header = rows.L.header;
(key=G1.key, values=G1.rows)
5.To display the result as a table
The DQL10 is based on DQL90 in the following topic.
- Solutions: by Justdoitcc

Notes

Summary

The same codes:

  • After the following expression:
```SQL
GROUP BY L.header AS G_L_header
```
Original Example10
```SQL
TABLE WITHOUT ID
      G_L_header AS "G_L_header",
```
Another Example11
```SQL
TABLE WITHOUT ID
      rows.L.header[0] AS "G_L_header",
```
Another Example12
```SQL
TABLE WITHOUT ID
      key AS "G_L_header",
```

Code DQL10_get_unique_links_of_headings_and_TABLE

Summary_code
title: DQL10_get_unique_links_of_headings_and_TABLE =>1.To flatten file.lists 2.To gather the links of the headers where each of the headings contains at least one list item or one task item 3.To filter by L.text 4.To group by L.header and `let G_L_header = rows.L.header;` (key=G1.key, values=G1.rows) 5.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      G_L_header AS "G_L_header",
      map(rows.L.header, (e) => link(e, meta(e).subpath))[0] AS "Heading",
      rows.F_subpath[0] AS "F_subpath",
      map(rows.L, (L) => choice(L.task, "- [" + L.status + "] " + L.text,  "- " + L.text)) AS "L.text"
     
FROM "100_Project/01_dataviewjs/01_by_example/Q88_header/Q88_test_data"

FLATTEN file.lists AS L
FLATTEN meta(L.header).subpath AS F_subpath
FLATTEN meta(L.header).type AS F_type
WHERE contains(L.text, "1")
WHERE F_type = "header"
GROUP BY L.header AS G_L_header

```

Screenshots(DQL10)



DQL20_get_unique_links_of_headings_and_groupIn_fLink_and_TABLE

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL20
_get_unique_links
_of_headings
_and_groupIn_fLink
_and_TABLE
file.lists yes 1.To flatten file.lists
2.To gather the links of the headers where each of the headings contains at least one list item or one task item
3.To filter by L.text
4.To groupBy L.header and let G_L_header = rows.L.header;
(key=G1.key, values=G1.rows)
5.To groupIn rows.file.link and let G_fLink = rows.file.link;
(key=G2.key, values=G2.rows)
6.To display the result as a table
The DQL20 is based on DQL10 in the topic.

Notes

Summary

The same codes:

  • After the following expression:
```SQL
GROUP BY L.header AS G_L_header
GROUP BY rows.file.link AS G_fLink
```
Original Example10
```SQL
TABLE WITHOUT ID
      G_fLink[0] AS "File",
```
Another Example11
```SQL
TABLE WITHOUT ID
      rows.rows.file.link[0][0] AS "File",
```
Another Example12
```SQL
TABLE WITHOUT ID
      key[0] AS "File",
```

Code DQL20_get_unique_links_of_headings_and_groupIn_fLink_and_TABLE

Summary_code
title: DQL20_get_unique_links_of_headings_and_groupIn_fLink_and_TABLE =>1.To flatten file.lists 2.To gather the links of the headers where each of the headings contains at least one list item or one task item 3.To filter by L.text 4.To groupBy L.header and `let G_L_header = rows.L.header;` (key=G1.key, values=G1.rows) 5.To groupIn rows.file.link and `let G_fLink = rows.file.link;` (key=G2.key, values=G2.rows) 6.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      G_fLink[0] AS "File",    
      rows.G_L_header AS "G_L_header",
      map(rows.G_L_header, (e) => link(e, meta(e).subpath)) AS "Heading",
      map(rows.rows.L, (L) => choice(L.task, "- [" + L.status + "] " + L.text,  L.text)) AS "L.text"
       
FROM "100_Project/01_dataviewjs/01_by_example/Q88_header/Q88_test_data"

FLATTEN file.lists AS L
WHERE contains(L.text, "1")
FLATTEN meta(L.header).subpath AS F_subpath
FLATTEN meta(L.header).type AS F_type
WHERE F_type = "header"
GROUP BY L.header AS G_L_header
GROUP BY rows.file.link AS G_fLink
```

Screenshots(DQL20)



DQL30_get_unique_links_of_headings_and_groupIn_fLink_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL30
_get_unique_links
_of_headings
_and_groupIn_fLink
_and_LIST
file.lists yes 1.To flatten file.lists
2.To gather the links of the headers where each of the headings contains at least one list item or one task item
3.To filter by L.text
4.To groupBy L.header and let G_L_header = rows.L.header;
(key=G1.key, values=G1.rows)
5.To groupIn rows.file.link and let G_fLink = rows.file.link;
(key=G2.key, values=G2.rows)
6.To display the result as a table
1.The DQL30 is based on the DQL20 in the topic.

2.The DQL30 is very similar to the DVJS10 with Another Example13B in the following topic.
- Solutions: by Justdoitcc

Notes

Summary

To modify the code

EX10: Original Example10
Summary_EX10
  • To gather list items or task items under any heading
  • To gather items where L.text contains “1” or “2”
```SQL
WHERE F_type = "header"
WHERE contains(L.text, "1") OR contains(L.text, "2")
```

EX11: Another Example11
Summary_EX11
  • To gather list items or task items under the heading where the heading contains “Question”
  • To gather items where L.text contains “breakfast” or “dinner”
```SQL
WHERE F_subpath = "Question" AND F_type = "header"
WHERE contains(L.text, "breakfast") OR contains(L.text, "dinner")
```

EX12: Another Example12
Summary_EX12
  • To gather list items or task items under the heading where the heading contains “Question”
  • To gather a task item where it is not fullyCompleted or To gather a list item where L.text contains “breakfast”
```SQL
WHERE F_subpath = "Question" AND F_type = "header"
WHERE (L.task AND !L.fullyCompleted) OR (!L.task AND contains(L.text, "breakfast")
```

EX13A: Another Example13A
Summary_EX13A
  • To gather list items or task items under the heading where the heading contains “Question”
  • To gather items where L.text contains “breakfast” or “dinner” or “feature”
```SQL
WHERE F_subpath = "Question" AND F_type = "header"
WHERE contains(L.text, "breakfast") OR contains(L.text, "dinner") OR contains(L.text, "feature")
```

EX13B: Another Example13B
Summary_EX13B
  • To gather list items or task items under any heading
  • To gather items where L.text contains “breakfast” or “dinner” or “feature”
```SQL
WHERE F_type = "header"
WHERE contains(L.text, "breakfast") OR contains(L.text, "dinner") OR contains(L.text, "feature")
```

EX14: Another Example14
Summary_EX14
  • To gather list items or task items under the heading where the heading contains “Question” with the desired structure
  • To gather items where L.tags contains “#Test/d05” or To gather items where L.outlinks contains “[[Note K]]”
```SQL
WHERE F_subpath = "Question" AND F_type = "header"
WHERE contains(L.tags, "#Test/d05") OR contains(L.outlinks, [[Note K]])
```

Code DQL30_get_unique_links_of_headings_and_groupIn_fLink_and_LIST

Summary_code
title: DQL30_get_unique_links_of_headings_and_groupIn_fLink_and_LIST =>1.To flatten file.lists 2.To gather the links of the headers where each of the headings contains at least one list item or one task item 3.To filter by L.text 4.To groupBy L.header and `let G_L_header = rows.L.header;` (key=G1.key, values=G1.rows) 5.To groupIn rows.file.link and `let G_fLink = rows.file.link;` (key=G2.key, values=G2.rows) 6.To display the result as a list
collapse: close
icon: 
color: 
```dataview
LIST 
     map(rows, (e) => 
         link(e.G_L_header, meta(e.G_L_header).subpath) + 
         "<br>" +
         join(
             map(e.rows.L, (L) => 
                 choice(!L.task, "⦁ " + L.text,
                     choice(L.task AND !L.completed AND !L.checked, "□ " + L.text,
                         choice(L.task AND !L.completed AND L.checked, "⚠ " + L.text,
                             choice(L.task AND L.completed,
                                 "▣ " + "~~" + L.text + "~~",
                                 L.text
                             )
                         )
                     )                 
                 )             
             ),
             "<br>"         
         )
     )
      
FROM "100_Project/01_dataviewjs/01_by_example/Q88_header/Q88_test_data"

FLATTEN file.lists AS L
FLATTEN meta(L.header).subpath AS F_subpath
FLATTEN meta(L.header).type AS F_type

WHERE F_type = "header"
WHERE contains(L.text, "1") OR contains(L.text, "2")

GROUP BY L.header AS G_L_header
GROUP BY "### " + rows.file.link[0] AS G_fLink
```

Screenshots(DQL30)

Part 1/2


Part 2/2


DVJS10_create_links_to_headings

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS10_create_links_to_headings a link like [[alphabet#a]] no To create the links to the headings

Notes

Summary

The same codes:

Original Example10
```JS
// M31.AR13 define s_link: \[[alphabet#a|a]\]
// #####################################################################
//let s_link =  "[[" + "alphabet" + "#" + "a" +"]]";//=>alphabet > a

//let s_link =  "[[" + "alphabet" + "#" + "a" +"|a]]";//=>a
//let s_link =  "[[" + page.file.path + "#" + char_from_a_to_z + "|" + char_from_a_to_z + "]]"; //=>a
dv.sectionLink(page.file.path, Heading, false, Heading); //=>a

```
Another Example11
```JS
// M31.AR13 define s_link: \[[alphabet#a|a]\]
// #####################################################################
//let s_link =  "[[" + "alphabet" + "#" + "a" +"]]";//=>alphabet > a

//let s_link =  "[[" + "alphabet" + "#" + "a" +"|a]]";//=>a
"[[" + page.file.path + "#" + Heading + "|" + Heading + "]]"; //=>a
//dv.sectionLink(page.file.path, Heading, false, Heading); //=>a

```

code DVJS10_create_links_to_headings

Summary_code
title: DVJS10_create_links_to_headings =>To create the links to the headers 
collapse: close
icon: 
color: 
```dataviewjs
// M11. define pages: gather all relevant pages
// #####################################################################
let pages = dv
    .pages('"100_Project/01_dataviewjs/01_by_example/Q88_header/Q88_test_data"')
    //.where((page) => dv.func.contains(page.file.name, "dic_"));     
//let pages = dv.current();


// M13. define s_filepath:
// #####################################################################
//let s_filepath = pages.file.path[0];


// M21. define aHeadings:
// #####################################################################
let aHeadings = ["a", "b", "c", "d", "e"];


// M31. output :
// #####################################################################
dv.table(
    [
        "File",
        "Link",
    ],
    pages.map((page) => [
        page.file.link,

        aHeadings.map((Heading) => [
            // M31.AR13 define s_link: \[[alphabet#a|a]\]
            // #####################################################################
            //let s_link =  "[[" + page.file.path + "#" + Heading + "|" + Heading + "]]";
            dv.sectionLink(page.file.path, Heading, false, Heading), //=>a
        ]),
    ])
);



```

Screenshots(DVJS10):


Reference

Summary

Emojis

dv.sectionLink


Related resources

Summary

1 Like

Thank you for your help.

But, the situation is a little different.
What I want to do is linking to the headers which are “generated by dv.header()”, not creating the links by dv.header().

1 Like
  • You could look at the DQL10 ,added on 2021-02-08.
  • It deals with the following problem.
    • How to get the links of the headers where each of the headings contains at least one list item or one task item?

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