In Silverbullet 0.94 this template:
tags:
- template
pageDecoration:
prefix: "🟩 "
hooks.top:
where: 'name =~ /^luoghi\//'
order: 502
---
${widgets.breadcrumb()}
let me put the “breadcrumb” content on the top part of the rendered page.
In Silverbullet V2 I seemed to understand that the same function was possible with the following code, but the widgets.breadcrumb() is not used.
Where am I going wrong?
widgets = widgets or {}
function widgets.breadcrumb()
local path = editor.getCurrentPage()
-- Funzione per suddividere la stringa in parti basate su "/"
local function split(str, sep)
local result = {}
for part in string.gmatch(str, "[^" .. sep .. "]+") do
table.insert(result, part)
end
return result
end
-- Divide il percorso in segmenti
local parts = split(path, "/")
-- Costruisce i breadcrumb escludendo l'ultimo elemento
local breadcrumbs = {}
local currentPath = ""
for i = 1, #parts - 1 do
if i == 1 then
currentPath = parts[i]
else
currentPath = currentPath .. "/" .. parts[i]
end
table.insert(breadcrumbs, "[[" .. currentPath .. "]]")
end
-- Restituisce i breadcrumb formattati
return table.concat(breadcrumbs, " > ")
end
event.listen {
name = "hooks:renderTopWidgets",
run = function(e)
return widgets.breadcrumb()
end
}