I want to find tags that exist in other page but not in current page. The following is my best attempt so far.
${template.each(query[[
from index.tag "tag"
where
_.parent == "page" and
_.name == "Other" and
_.name not in
${query[[
from index.tag "tag"
where page == _CTX.currentPage.name
]]}
select {name=_.name}
]], template.new[==[
#${name}
]==])}
Lua error: Parse error at pos 138
template.each(query[[
from index.tag "tag"
where parent == "page"
and not table.includes(
editor.getCurrentPageMeta().tags,
name
)
select {name=name}
]], template.new([==[
#${name}
]==]))
The in keyword in lua is only used for for-loops, it does not work for tables like that. You need table.includes() to check if a table contains an item. And then instead of a nested query you can get the current page tags via editor.getCurrentPageMeta().tags.
Not sure what the _.name == "Other" clause was for, that would only include the tag called “Other” if it exists so I left it out.
I changed my structure to use tasks instead of tags. It seems tasks are not available in editor.getCurrentPageMeta(). Is it possible to get the following query to work?
I try to find all tasks on page meta/my-checklist that are missing in editor.getCurrentPage() based on name equality.
${query[[
from index.tag "task"
where page == "meta/my-checklist"
and not table.includes(
query[[
from index.tag "task"
where page == editor.getCurrentPage()
]],
name
)
]]}
Do you mean all tasks on pages tagged with meta/my-checklist? Because if you actually mean only tasks in the page called “meta/my-checklist”, you don’t need the second condition with the table.includes:
${query[[
from index.tag "task"
where page == "meta/my-checklist"
]]}
I think this is what you are looking for:
${query[[
from index.tag "task"
where table.includes(itags, "meta/my-checklist")
and page ~= editor.getCurrentPage()
]]}
This will get all tasks that include the tag meta/my-checklist (the itags table contains all tags of the task + all tags of the parent page) and the page the task appears on is not the current page (page ~= editor.getCurrentPage()).