Render link from view.js

What I’m trying to do

I’m having problems to render a link to a note from a view.js file that is executed from a dataviewjs block.

This works but doesn’t allow me to provide a custom link text:
dv.el("a", dv.fileLink("2022-10-20"));

This shows the correct custom link text, but the link does not work:
dv.el("a", "back", {'attr': {'href': dv.fileLink("2022-10-20")}});

Any ideas?

Some context why I’m doing this:
In my daily notes I want to show a dynamically rendered header with links to next and previews days. The header is generated in the view file and linked to the note like this:
$= await dv.view("views/daily-note")

By not hardcoding the header I can modify the header any time and the changes will be in all daily notes.

My point is not specific to view.js (I don’t have experience with the use of dv.view()), but why you use, for the case, the dv.el()? You don’t need the a attribute to link work.
(you can use dv.span(dv.fileLink("2022-10-20")))

Second point is related with dv.fileLink(): as said in docs, dv.fileLink(path, [embed?], [display-name]) you can specify the display name… So, you need a path and the wanted display text:
dv.fileLink("2022-10-20", false, "back")

1 Like

Thanks! I forgot to add the false parameter! If you just write dv.fileLink("2022-10-20, "back") nothing is displayed!

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