In a template that must be substituted, add the following code at the top:

{{ {{#ifeq:{{<includeonly>subst:</includeonly>void}}|{{void}}|void|Error:must be substituted}}| template name }}

Example: Template:Demo of template that must be substituted (backlinks, edit).

"{{Demo of template that must be substituted}}" gives "This template must be substituted. Replace {{Demo of template that must be substituted}} with {{subst:Demo of template that must be substituted}}.Template body" [୧]

while {{subst:Demo of template that must be substituted}} gives "Template body".