efemkay / obsidian-modular-css-layout

CSS Layout hack for Obsidian.md
https://efemkay.github.io/obsidian-modular-css-layout/
GNU General Public License v3.0
918 stars 74 forks source link

How do I create cards dynamically (dataviewjs)? #73

Open Dartaltram opened 7 months ago

Dartaltram commented 7 months ago

I have several notes with the "#card" tag and want to summarise them in a card gallery, but when I print the correct syntax (as opposed to manually typing it out) the result is a simple markdown nested list

Note source

# Title!

- ## Card #mcl/list-card
    - some text
    - some text

```dataviewjs

    const cards = dv.pages('"zzzzzzzzzz"').file
        .where(c => c.tags.includes('#card'))

    dv.span(
        "- ### PLACE #mcl/list-card\n" +
        "    - aaaaa\n" +
        "    - bbbbb\n"
    )
\```

---

`$= '- ### another PLACE #mcl/list-card\n    - aaaa\n    - bbb\n'`

---

<%* tR += "- ### PLACE #mcl/list-card\n    - aaaaa\n    - bbbbb\n" %>

As can be seen the first lines are an example of a manually typed out card

Then there's a block taking all the cards from the test folder "zzzzzzzzzz" and bearing the tag "#card". The original idea was to print them in a for cycle but let's start small.

Trying to print the syntax with a dv.paragraph or a dv.span didn't work correctly and neither does using an inline dv, as shown in the picture below. Applying a template like the one in the last line WILL work, but it is obviously not dynamic

Current Behaviour

image

Here I put the result in Reading View after applying the template

Suggestions?

efemkay commented 7 months ago

unfortunately i have very little working knowledge of dataview syntax. not sure if that's even possible.

templater would translate the template syntax into markdown upon creation (of the note), hence why it works. as far i know, dataview would do that dynamically and doesn't permanently convert to markdown syntax. you can try obsidian discord dataview thread in case it is somewhat possible