core: add support for 'optional include' templates.

Fixes issue #471.