Hi guys, I was wondering if Macros can be used for the following scenario:
search for and find an uniquely-distinguishable block and retrieve it’s Block-ID (using a database query from the macro itself?);
build the {{embed ((block-id))}}
I would like to tell the Macro {{{embed “uniquely-distinguishable text in Block or property” /today }}} and get as a result a block with en embed just like I would do with Ctrl+E/Ctrl+V
Ex:
Now I know I can get the Block-ID from a Complex Query but how to pass it as an argument to a macro?
I didn’t find much help online on Logseq Macros and I am not a developer so my understanding would be limited anyway but I thought that I can define a complex query with a function or some name in config.edn and call it from the macro directly…
I didn’t quite get what you were proposing: so I define a macro in which I write the simple query in which I search for some search terms but then I got confuse what is (sample 1)…
I actually stumbled upon the github issue about complex queries not able to be run in macros cause that was actually what I was looking for.
My situation requires a complex query because I need to filter the found block for children and get the block-id of the last immediate child of said parent block.
With a general situation your solution should work, at least the non-CSS part.
So i basically want to perform a complex query that would return the last direct child of a parent-block with distinct name and use that block-id in an embed created by a macro
I have solved, in other thread, the query issue (thanks @Siferiax ) but I still wanted to reuse the code for other sections of my Daily Journal where i usually insert new notes so I can quickly capture straight to those sections.
So, I would call, in the Contents Page in the Right Sidebar: {{get-embed "### Journal Entries" <%today%>}} {{get-embed "### Today's Metrics" <%today%>}}
This was my idea.
So I thought a Macro can call a query saved in config.edn and use the parameters $1, $2 to tailor the query, then create the string:
Yeah, would be very cool if something like this is possible.
Invoking queries defined in the config file in general. I think lots of people may like that.
I just find it to be an elegant solution if the macro can call a query or a function and get a result to a block. I am, of course, doing it differently atm but I try to optimize, reduce steps, future-proof, etc.
I am currently using tabs I leave opened each morning and switch to when I want to input a note into a specific section because, when zoomed in, you get that last line where you click and you get a new bullet, instead of Ctrl_Clicking the previous Block, then press Enter Twice to achieve the same.
Again, it was an exploration of how to do things more elegantly and reduce steps between idea and noted info.
I wasn’t expecting that you can’t run complex queries from macros, because simple ones you can…
the queries are executed passing those parameters as inputs
If we come with a nice generic design, all the pieces are there, it only remains to connect them (e.g. the config file is too heavy, queries don’t belong there). If you are interested, I can open a separate thread, and leave this one for the embedding part.
Complex Queries in Macros is not possible so this thread is past its prime. Feel free to use this or open new thread. I agree config.edn for everything is not a good solution. I even think Custom Commands should have a separate file.