Generate explicit hierarchy out of properties

If you share some complex hierarchy topic, I may prepare some guide.

I don’t have particular topic in mind but I struggle to create some hierarchy of information, todos, ideas. Todo’s are connected to many ideas, ideas are connected to many todo’s.
For me complex hierarchy issue is when I try to manage my todo’s. I have different areas of interest like cooking, home, work, productivity, learning English, reading books, etc. I noticed that traditional tree of documents is not enough to create hierarchy, but tags are also not enough. I created #todo and as a subpage #todo/now #todo/next. But I also want to have #work/todo #productivity/todo pages. So, #todo/next page and #work/todo are different and separate pages. And another layer of information is differentiation between ideas and physical things. Increasing productivity is an idea, connected to self-improvement. Should I have another page: self-improvement? While learn how to use Logseq is connected to idea: productivity, and todo. It is and activity.

Good solution for me would be to have ability to see different trees based on properties, so that the same page could have different places in different trees: ideas tree, activities tree, physical objects tree (book about productivity is a physical object to buy), etc. the same page: “now” could appear as todo/now and productivity/now depending on what tree I display. And productivity page could be at different levels of hierarchy depending on tree displayed:

This way naming pages like this: productivity/now would be not necessary because properties would manage hierarchy.

I’d like to be able to switch easily between different tree views to have easy access to them, for example from panel icon.

It would be like virtual trees not physical pages trees.

I visualize my information rather like multidimensional connections not like a tree but this would be to difficult to achieve as a way of navigation in a program.

The best solution would be to be able to create hierarchies dynamically by drag and drop to some virtual hierarchy space.

Actually we should stop call it hierarchy (unless someone wants to treat it like that) and call it “connections views”.

Without a particular example, it is difficult to give particular advice.

This is an issue beyond this thread. Consider opening a separate one.

It would really help to put some order in the terminology itself:

  • TODOs and ideas are information themselves.
  • TODOs may have sub-TODOs, but that’s all about their hierarchy (see lower).
  • There are two types of ideas:
    • Specific ideas that you come with: These are like TODOs.
    • Abstract ideas that pre-exist: These are the best material for multiple hierarchies.

Unless you mean the same connection inverted, only one direction should be valid.

Libraries (e.g. of books) know that very well. Fixed hierarchies remain useful, but they are very limited. The solution is graphs.

This won’t work well, because now and next change dynamically.

These should not be pages, but queries that filter your TODOs.

Now you are on topic, as far as this thread is concerned.

I get “Access denied” when trying to open that link.

This is again beyond this thread.

Overall, consider this approach:

  • Think about the possible virtual trees that you would like to generate.
  • For each one of them, find a property that describes the relationship among its nodes (e.g. type, category, container, subtopics, sections, etc.)
    • TODOs are not nodes, but leaves. A TODO:
      • may appear almost anywhere in your pages
      • doesn’t have pages as children
  • Use those properties consistently while creating your pages.
  • Use one macro for each tree, built around its defining property.

If you decide to try that approach, we may use it as a point of reference.

No. Queries results can’t be sorted manually. I want to have todo pages because I don’t use to do option. I know that something is todo when I have it on todo page and I use references from text to todo page. When there is a reference on todo page it means I must do something about it.

I added direct link to jpg.

Use one macro for each tree, built around its defining property.

I am new to Logseq and I wish there was a video about it, about creating macros. I will customize it.
If possible, please use your own properties and show how to write and run macros to display trees. And how to create an easy access to them. I don’t have so many data in Logseq yet. It will be easier for me to use properties in a meaningful way if I know what can be utilized for.

I found only one video about properties
How to use properties and templates in Logseq by OneStutteringMind, but it doesn’t cover the topic in depth.

Currently, I can only clear up how to use the single macro for this thread:

  • A macro is defined only once, by providing its name and output. For the trees, you only need to copy the following line and paste it inside the configuration file config.edn (found in the first page of Logseq’s Settings), inside section macros{}.
:pagetree "<div class='kit pagetree' data-kit='pagetree' data-node-prep='$1' data-node-prop='$2' data-leaf-prep='$3' data-leaf-prop='$4'>pagetree</div>"
  • A defined macro is called as many times as you need, by opening double curly braces in a note, and writing inside the name of the macro (here pagetree) followed by the desired parameters (called arguments), like this:
{{pagetree arg1, arg2, ... }}

Make sure each time to replace the part arg1, arg2, ... with a comma-separated series of the actual arguments (i.e. the desired tree’s characteristic property, preceded by its type), like in the examples provided in the OP:

{{pagetree to, children}}
{{pagetree from, broader, is, refs}}

Wow, thank you for your valuable work. I have to try this out!

Hi, thank you for sharing this neat trick.

From the example below (taken from one of the examples), I would sometimes only want to show the pagetree where parent:: [[man1]], so that the tree would look like the following:


Would this be doable with the current code?
  parent:: [[man1]]
  parent:: [[man2]]
  parent:: [[man2]]
  parent:: [[man1]]
  children:: [[man1]], [[woman1]]
  children:: [[man2]], [[woman2]]
  parent:: [[grandfather1]]
  parent:: [[grandfather2]]
  parent:: [[grandfather1]]
  children:: [[boy2]], [[girl1]]
  parent:: [[grandfather2]]
  children:: [[boy1]], [[girl2]]

EDIT: The motivation for this question is I would like to keep the parent and child property all throughout my graph for linking pages.

Welcome. Currently the code is limited by the syntax of macros, so there is no placeholder for defining a page as the single root. But if you can write some code, you can define in PageTree.roots.queries a query that returns a specific page as a starting point (in your example man1). Using this query, the tree would look like the following:

  • man1
    • boy1
    • girl2

Sadly, I do not know enough javascript and datalog to get this working quick. I might have to go look into this again over the weekend. Thank you.

Here is a quick workaround:

  • Find this line in the code:
        const roots = pgRoots.get(nodeconfig);
  • Replace it with these lines:
        const curpage = ( === "current") && logseq.api.get_current_page();
        if (curpage) curpage["original-name"] = curpage.originalName;
        const roots = (curpage) ? [curpage] : pgRoots.get(nodeconfig);
  • Add this macro inside file config.edn, inside macros{}:
    :curpagetree "<div class='kit pagetree' data-kit='pagetree' data-node-prep='$1' data-node-prop='$2' data-leaf-prep='$3' data-leaf-prop='$4' data-page='current'>pagetree</div>"
  • Visit the desired page
    • e.g. man1
  • Use the macro, either in the page or on the right sidebar
    • e.g. {{curpagetree from, parent}}
      • the result of the example:
1 Like

bro do you know any tutorial for this? looks like is what i was seeking in a note app, but im not tech savy
Is there a page/github that we can track that code ?

  • Everything is available in the first post and the links there:
    • examples
    • code
      • The whole code is public within posts in this forum.
        • It has not changed for many months now.
        • Nobody has reported any problem so far.
    • instructions
      • Read the posts
      • Follow the steps
        • If you get stuck at any step, let me know.

bro im testing here and looks very promissing, may i ask you some questions that i have ?
so just a example i have a note called “Despesa Publica”
broader:: [[finPublica]]
broader:: [[Despesa Publica]]
narrower:: [[Divida Flutuante]], [[Divida Fundada]]
broader:: [[Despesa Publica]]
broader:: [[Divida Publica]]

Output on Despesa

  • {{pagetree(from,broader)}}

Divida stays sibling of Divida, altough should be child
Is there a way to make narrower and broader work together ?
I saw that the code works as expected just looking to “broader” attribute, but if it could take in consideration the “narrower” this code would be the god of hierarchies PKMs.

another possibility, if not using “narrower” property, would be in broader property, you could set more than one links, and the code would handle like this:

broader:: [[finPublica]]
broader:: [[Despesa Publica]]
narrower:: [[Divida Flutuante]], [[Divida Fundada]]
broader:: [[Despesa Publica]], [[Divida Publica]]
broader:: [[Divida Publica]]

Output on Despesa
Now it duplicates

instead it could understand the tree hierarchy taking the nearest one as broader and then just:

just an parenthesis here, ofc these suggestions/feature request(if i may) that i made look dumb with few notes, but bro when you hit a lot of notes (i have more than 2k), that sense of direct hierarchies kinda lost, and that code would help a lot

And congrats for that fantastic work you made, i really appreciated was the far most well done implementation of hierarchies in any pkm that i know. And i searched a lot for this, glad that i landed here

  • Despite its complexity, this implementation is dumb, it doesn’t understand anything at all.
    • That includes complimentary properties and redundant relationships.
    • It doesn’t even understand circular relationships.
      • It simply stops repeating after reaching the provided limit.
  • The code could be modified to support the requested features.
    • The needed effort seems disproportional to the gains.
    • I’m currently looking to improve the underlying engine, so as to enable the user to direct the whole process.
      • That could result in something much better than your “god of hierarchies PKMs”.

Regard the add of another property i agree that the effort could be disproportional to its gains and could turn code way more complex.
But why (honest question) do you think the second idea is bad as a feature request ofc ?
because not always we know the exactly parent of the note in a big graph, so we put more than one on the child property note, and code could take the short path without duplicate as it is doing, but again just giving ideas to improve, not trying to say the approach now is bad or wrong.
By the tone of the last phrase of your answer i feel that you may felt insulted somehow or didnt like what i said, but was not my intention.
I really appreciated what you did, congrats again

Plenty of misunderstandings in that one.

Without being tech savvy, can only guess.

The current approach is merely the technically easy one, far from the desired one.

Never assume any tone for things written in a forum, rather stick to the content itself. It is the responsibility of the poster to communicate what they think through prose, rather than through literature. In that instance, no tone was meant.

Nobody can feel what someone else feels. In that instance, I actually felt nothing.

I never said that is bad. I just happen to aim at a higher level, therefore I cannot adopt your description without quotes.

I am the one who asked for feedback and I appreciate all of it (as long as it remains on topic).

1 Like

btw, i will adjust my notes to use that code, do you think is possible logseq in the future updates break something/or turn unusable ? or since is relying on java script is kinda of independent stuff ?

This code uses Logseq’s API to query the database for the needed data. In the rare case that a future version changes these conventions in an incompatible way, someone should adapt the respective API call and queries to the new conventions. Meanwhile, the previous versions will continue working normally. Therefore, there is a theoretical chance for troubles, but too small to worry.

thanks and last question, i will not bother you anymore rsrsrs

is possible to use that command {{pagetree from, broader}} with any “AND” clause , that will only show the pagetree of notes with giving tag/s ?