As for your first question, you can use "{:" instead of "{#shelf:".
Your template seems to do what you want. However, the performance will be less than ideal. This is a case where you should use a custom template function, which will be at least 100 times faster. However, that would require you to write the function in python using calibre's template function editor (preferences -> template functions), which you might not be prepared to do.
|