How to Execute a Codeblock Inside DataviewJs?

It depends on when and where the other codeblock is parsed and executed.

So the easiest option is simply to try it out, and see what happens. This thread shows an example of doing a Tasks code block from within Dataviewjs.

Personally I often use this at the end of my dataviewjs:

else
  dv.paragraph(`~~~\n${ result.error }\n~~~`)

This showcases three aspects:

  • First of all the usage of tildes instead of backticks which is perfectly legal for code block fences. It saves you a whole lot of escaping backticks
  • The usage of dv.paragraph() to output the code block back to the page
  • The usage of ${ result.error } to present a random variable within the output

So you could try something like the following:

```dataviewjs
dv.paragraph(`
~~~page-gallery
... here goes your gallery stuff ...
~~~
`)
```

And if you need to do other javascript stuff in front, please do so, and if you want that listed within the code block, use something like: ${ myVariable }.

1 Like