如何在不使用#invoke 的情况下仅在包含模板时替换魔术词?

How can I substitute a magic word only when transcluding template without using #invoke?

我正在尝试制作一个显示放置时间的模板。我试过这个:

This is a template ({{<includeonly>subst:</includeonly>CURRENTTIMESTAMP}})

但是当嵌入时它会显示为 This is a template ({{subst:CURRENTTIMESTAMP}}) 而不是替换时间戳。然后我尝试了

This is a template ({{{{{|safesubst:}}}CURRENTTIMESTAMP}})

但这并不能替代它;时间戳会不断更新。接下来,我尝试了

This is a template ({{<includeonly>{{{|safesubst:}}}</includeonly>CURRENTTIMESTAMP}})

但没有骰子。

我知道 {{#invoke:}} 可以,但我没有那个选项。有人可以帮我吗?

考虑模板的存储方式。如果您递归地替换模板,模板的内容将存储在包含页面的维基文本中,CURRENTTIMESTAMP 替换为实际时间戳。如果你不替换模板,维基文本将只包含 {{MyTemplate}},并且编辑的时间戳不会存储在任何地方;当解析器呈现文章并遇到 CURRENTTIMESTAMP 时,它将只使用当前时间戳。没有办法解决这个问题,#invoke 与否。

你可以做的是把时间戳变成一个参数,所以在包含的页面中你可以写{{MyTemplate|{{subst:CURRENTTIMESTAMP}}}},然后时间戳就会存储在页面中。您可以创建具有该确切内容的包装器模板,这样用户只需键入 {{subst:MyTemplateWrapper}},这样会更容易一些。尽管 that's a bit more involved.

,您甚至可以在不使用替换的情况下使模板显示错误/添加错误类别