How to create nested elements? #701
Replies: 4 comments 7 replies
-
The
|
Beta Was this translation helpful? Give feedback.
-
Sorry to post on an old disucussion @blacksmithgu, but this seemed like an appropriate place. |
Beta Was this translation helpful? Give feedback.
-
I have a good workaround for this issue if (input && dv) {
dv.el("div", "", { cls: "dataview alancunha26-root" });
const container = document.querySelectorAll('.dataview.alancunha26-root')[0];
container.innerHTML = `
<div class="card">
<strong>Alan Cunha</strong> it works!
</div>
`;
} |
Beta Was this translation helpful? Give feedback.
-
Riffing a little bit on @alancunha26's solution, you can actually create nested lists by using only the if (input && dv) {
const listRoot = dv.el("ul", "");
dv.el("li", "Something at the root level", {container: listRoot});
const nestedListRoot = dv.el("ul", "", {container: listRoot});
dv.el("li", "A nested item", {container: nestedListRoot});
} This will create a nested list like this
I've used this to create a file tree viewer for automated maps of content with links to documents using Dataview. That full example is available here: https://gist.github.com/jessecureton/d6f73ab8b03bd76ac92d3fa7a7e334b8 |
Beta Was this translation helpful? Give feedback.
-
I want to have a card grid showing my books. I see there’s
dv.el()
which is used to create an arbitrary HTML element, but I’m not sure how to use it to create nested ones.Speaking in HTML, I want something like this:
I just put some codes that I'm willing to use. It's not the actual code... I mean, it doesn't matter if I should use
dv.span(text)
or<span>text</span>
; I'm looking for the "container" element.I also posted this in Obsidian forums
https://forum.obsidian.md/t/how-to-create-nested-elements-with-dataviewjs/27788
Beta Was this translation helpful? Give feedback.
All reactions