Skip to content

Commit f5a4e7e

Browse files
authored
Merge pull request #3649 from obsidian-tasks-group/issue-3647-fake-inherit-tags
docs: Show 'group by function' inheriting tags from parent task
2 parents ec274b3 + a5c1612 commit f5a4e7e

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

docs/Queries/Grouping.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,17 @@ group by function task.tags.filter( (tag) => ! tag.includes("#tag") )
754754

755755
- Create headings for all tags that do not contain "#tag".
756756

757+
```javascript
758+
group by function \
759+
if (task.tags.length > 0) return task.tags; \
760+
return task.findClosestParentTask()?.tags ?? [];
761+
```
762+
763+
- Group tag-less child tasks by any tags on their parent task:
764+
- If the task has any tags on its own line, then group by those tags.
765+
- Otherwise, look for the first parent task, and group by its tags.
766+
- If there is no parent task, treat the tags as empty.
767+
757768
<!-- placeholder to force blank line after included text --><!-- endInclude -->
758769

759770
These are more complicated examples, which you might like to copy if you use tasks with [nested tags](https://help.obsidian.md/Editing+and+formatting/Tags#Nested+tags) and wish to group them at different tag nesting levels.

tests/Scripting/ScriptingReference/CustomGrouping/CustomGroupingExamples.test.other_properties_task.tags_docs.approved.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,16 @@ group by function task.tags.filter( (tag) => ! tag.includes("#tag") )
3232

3333
- Create headings for all tags that do not contain "#tag".
3434

35+
```javascript
36+
group by function \
37+
if (task.tags.length > 0) return task.tags; \
38+
return task.findClosestParentTask()?.tags ?? [];
39+
```
40+
41+
- Group tag-less child tasks by any tags on their parent task:
42+
- If the task has any tags on its own line, then group by those tags.
43+
- Otherwise, look for the first parent task, and group by its tags.
44+
- If there is no parent task, treat the tags as empty.
45+
3546

3647
<!-- placeholder to force blank line after included text -->

tests/Scripting/ScriptingReference/CustomGrouping/CustomGroupingExamples.test.other_properties_task.tags_results.approved.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,22 @@ Create headings for all tags that do not contain "#tag".
6161
#project/project1
6262
====================================================================================
6363

64+
65+
group by function \
66+
if (task.tags.length > 0) return task.tags; \
67+
return task.findClosestParentTask()?.tags ?? [];
68+
Group tag-less child tasks by any tags on their parent task:
69+
If the task has any tags on its own line, then group by those tags.
70+
Otherwise, look for the first parent task, and group by its tags.
71+
If there is no parent task, treat the tags as empty.
72+
=>
73+
#context/home
74+
#context/work
75+
#multiple-tags1
76+
#multiple-tags2
77+
#project/project1
78+
#tag
79+
#tag/subtag
80+
#tag/subtag/sub-sub-tag
81+
====================================================================================
82+

tests/Scripting/ScriptingReference/CustomGrouping/CustomGroupingExamples.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,15 @@ describe('other properties', () => {
626626
'group by function task.tags.filter( (tag) => ! tag.includes("#tag") )',
627627
'Create headings for all tags that do not contain "#tag"',
628628
],
629+
[
630+
`group by function \\
631+
if (task.tags.length > 0) return task.tags; \\
632+
return task.findClosestParentTask()?.tags ?? [];`,
633+
'Group tag-less child tasks by any tags on their parent task:',
634+
' If the task has any tags on its own line, then group by those tags.',
635+
' Otherwise, look for the first parent task, and group by its tags.',
636+
' If there is no parent task, treat the tags as empty.',
637+
],
629638
],
630639
SampleTasks.withRepresentativeTags(),
631640
],

0 commit comments

Comments
 (0)