The following is a comprehensive tutorial how to build letter index with active/inactive letter-buttons depending on actual presence of documents in container(s) being the subject of interest/search.
Prerequisites are three chunks, for example, named: "empty", "one-letter", and "index".
"empty" chunk is used for generating empty output -- its content should be something like:
where [+none+] stands for non-existent TV name which, at a runtime, will be replaced by Ditto with empty text.
"one-letter" chunk is used for generating listing of documents whose filtered TV (lastname in the above-post) starts with specific letter, its sample content might be as follows:
"index" is used for generating A B C... Z active/inactive buttons, I will build its content at the end.
You need to put into content field of each A, B, C, ..., Z document Ditto call:
<ul>[[Ditto? &parents=`49` &depth=`1` &display=`all` &tpl=`one-letter` &noResults=`empty` &filter=`lastname,[*pagetitle*],11` &sortBy=`lastname` &sortDir=`ASC`]]</ul>
Next you need to build A B C ... Z index in your ABC document; for this purpose place into the content of this doc the following Ditto call:
<!-- manually build ALL link here -->
[[Ditto? &parents=`109` &depth=`1` &display=`all` &tpl=`index` &sortBy=`pagetitle` &sortDir=`ASC`]]
And finally, "index" chunk, the most sophisticated part of this task:
[+phx:if=`[[Ditto? &parents=`49` &depth=`1` &tpl=`one-letter` &noResults=`empty` &filter=`lastname,[+pagetitle+],11`]]`:is=``:then=`[+pagetitle+]`:else=`<a href="[~[+id+]~]">[+pagetitle+]</a>`+]
Of course, the above only looks like a sophisticated thing, but actually it is a simple if-then-else statement expressed in PHx terms. Before building each letter-button in the index, you need to check whether documents starting from this letter exist or not. This part is performed by if-part of PHx. If Ditto returns no output (there are no documents), then the letter as a static text is rendered (then-part of PHx). Otherwise (else-part of PHx), linked letter is rendered. Done.
The advantage of this solution is that it requires neither extender nor ugly-looking url stuff.
Edit: this was a long post so some inconsistencies appeared in it, but hope I removed them all.