Add text to <p> tag with DataView?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

So I want to have DataView generated text inside a paragraph tag, the thing is obsidian doesn’t register ``` as code when inside an HTML tag, so I’m trying to get this to work outside the p tag and add the text programmatically. Is it possible with JS? that’s what I want to achieve (maybe there’s better way to do it):
image
The gray one is the result I want, I can do it with that because the creation date doesnt chnage.
The code for the p:

<p style="font-size:13px; color:gray" id="md">
Created: 12th July 2023 <br/>
</p>

Things I have tried

I have tried googling without success, so I came here

Would an inline query solve your query? The triple backticks are for larger queries but you can also do both inline queries and inline javascript stuff using Dataview.

If I understand correctly, you should check out the dv.el() function.

Something like this inside a dataviewjs code block may fit your needs:

var text = "Created: 12th July 2023";
var a = {style: "font-size:13px; color:gray"};
dv.el("p", text, {attr: a});
1 Like

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