Tables and Clickable Links

Hi, Apologies if this is a very simple question and/or not in the right place. I’m loving playing with the v2 SB and I’m already making a lot of progress but I’m stuck with something.

I have a query where I can pull all the pages tagged with ‘japan’ and ‘phrases’ and display them as a nice table. (1) below.

I have a query where I can pull all the pages tagged with ‘japan’ and ‘phrases’ and make the names clickable links. (2) below.

But I can’t figure out how to write a query where I can have a nice table AND make the names clickable links and I’m looking for a bit of help. I reckon I’m 90% there (probably) but can’t make the last 10%.

Thanks,

Nick.

(1)
${query[[
  from p = index.tag "japan" and index.tag "phrases"
  order by p.name
  select {
    Name = p.name,
    Description = p.description
  }
]]}

(2)

${template.each(query[[
  from p = index.tag "japan" and index.tag "phrases"
  order by p.name
  select {
    Name = p.name,
    Description = p.description
  }
]], template.new[==[
     [[${Name}]]  ${Description} 
]==])}

Not sure, if understood correctly, but this could deliver what you describe :slight_smile:

${query[[
  from p = index.tag "japan" and index.tag "phrases"
  order by p.name
  select {
    Name = "[[" ..p.name .. "]]",
    Description = p.description 
]]}
1 Like

however, on second thought: What do you want to achieve with this “and” and the second index.tag?
Trying this on my side that just delivers values from the second one…

Aha! You’re a genius. That did it perfectly! Super job.

OK so the ‘and’ and the second index.tag… I’m going to Japan in Oct and so I have a series of notes. Some about ‘phrases’ and some about ‘accommodation’ and some about ‘travel’ - so I want to have 3 separate tables, each about ‘japan’ but obviously also about ‘phrases’, ‘accommodation’, or ‘travel’ in turn. The second and seems to get me that - or at least it does right now.

Hmmm. You’re correct. It seems to just care about the second tag. So how do I do a proper search for BOTH tags (or any arbitrary number of tags)?

Oh, no, no. I’m not a genius, the real genius is @zef :slight_smile:

Ok, so, if you are searching for all Pages containing the one or the other tag, you could use something like this (think the other way round):

query[[from index.tag "page" where table.includes(tags, "japan") or table.includes(tags, "phrases") ]]

Brill! That’s it. Perfect. Thanks so much!!!

Nice. Do you know if its possible to dynamically generate the table.includes()?

i.e. pass a function a table of tags then auto-generate the query based on that table?

In fact, I already had a similar requirement. But I could not figure out a proper way to put something “dynamic” within the queryphrase.

However, I have a workaround for you. Not very elegant or performant, but should solve the problem:
Just run the query multiple times and add all results to a table, like so:

```space-lua
function MyMultiQuery (taglist) 
  local result = {}
  for i, myTag in ipairs(taglist) do
    for _,v in ipairs( query[[ from index.tag "page" where table.includes(tags, myTag ) ]] ) do 
      table.insert(result, v)
    end
  end
  return result
end
```

The expression will look like ${SpecialTestQuery( {"japan", "phrases"} )} for example. However, you could generate the List of tags to search via script, too.

Thanks for that - I had wondered about a similar solution. As you say, not particularly elegant, but does the job.