List Subpages ordered by letter

Hi, I want to make a glossary like overview of subpages.

I’ve tried to create it with a template:

# Glossar
{{#each @c in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
}}
## {{@c}}

{{{page where name =~ /SomePage\/@c.+/}}}
{{/each}}

But I can’t get any pages listed because it seems like I can’t reference @c inside the regex expression.

Has somebody achieved something similar?

Hi there,

Based on @zef 's following quote:

You can give this a try.

{{#each @c in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
}}
## {{@c}}
{{{page where name =~ "^SomePage/" + replace(@c, /(.+)/, "$1")}}}

{{/each}}

Awesome thx, this is perfect and works like a charm.
This is how it looks in the end:

# Glossar
{{#each @c in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']}}
## {{@c}}
{{#each {page where name =~ "^SomePage/" + replace(@c, /(.+)/, "$1")}}}
- [[{{name}}]]
{{/each}}
{{/each}}
1 Like

Nice, I’ll adapt this for a page-referencing glossary!
Just something I noticed: the replace call in this template is just replacing the current character with itself; Omitting the function call cleans up the code a bit:

{{ ({page where name =~ "^SomePage/" + @c}) }}