dvargas92495 / SmartBlocks

Useful examples from developer community for Roam42 SmartBlocks
147 stars 7 forks source link

List Pages in a Namespace #184

Open zsviczian opened 3 years ago

zsviczian commented 3 years ago

I added a new issue with a slightly alternative (and better) solution: see Issue 185

✂️ Copy of your #42SmartBlock from Roam

function search(value, index, array) { title = value[0]['title']; if (title.startsWith(namespace)) roam42.smartBlocks.activeWorkflow.outputAdditionalBlock('[['+title+']]', false); }```%>

📋 Describe the SmartBlock

Lists pages in a namespace, or more generically lists pages beginning with provided input.

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

None

📷 Screenshot of your #42SmartBlock workflow/template from Roam

image

💡 Additional Info

I am 100% sure there is a nicer solution. This is the impatient man's solution... I did not have energy to read through and learn the query language. I think the solution is to use a clever predicate... but can't figure out how, and I am happy the SB works... so moving on. If you want further reading, this is where you find it:

Should you find a nicer solution, please let me know, I'd like to learn from a working example.

RoamStack commented 3 years ago

As I have no idea how to do a pull request for a change here (sorry, I'm a Github noob), I'm going to leave this improvement as a comment. Special thanks to @dvargas92495 for helping me to make this SmartBlock work in the Roam desktop app.

- #42SmartBlock Namespace
    - <%NOBLOCKOUTPUT%><%JA:```javascript
return smalltalk.prompt("Roam42 SmartBlocks", "Namespace?", "roam/").then((namespace) => {
window.roamAlphaAPI.q('[:find (pull ?e [*]) :where [?e :node/title] ]').forEach(search);
function search(value, index, array) {
title = value[0]['title'];
if (title.startsWith(namespace))
roam42.smartBlocks.activeWorkflow.outputAdditionalBlock('[['+title+']]', false);
}
});```%>