我可以获得一个 mediawiki 模板来根据其在页面上的位置更改显示文本吗?

发布于 2024-09-14 05:22:49 字数 293 浏览 2 评论 0原文

我想创建一个 MediaWiki 模板,它根据页面上的位置显示不同的文本。

具体来说,它在第一个标题之前应显示类似“此模板适用于整个页面”的文本,

或者,如果它位于页面上的某个部分内(在标题之后)它应该显示类似“此模板特别适用于本节”的文本。

我知道有些模板使用“If”(例如 If pagename);有什么方法可以检测模板在页面上的位置吗?

I want to create a MediaWiki template which shows different text depending on where it is on a page.

Specifically, it is before the first heading it should show text like, "this template is applicable to this whole page"

Alternatively, if it is within a section on a page (after a heading) it should show text like, "this template is specifically applicable to this section".

I know there are templates that make use of "If" (like If pagename); is there any way of detecting the template's location on the page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中楼上月下 2024-09-21 05:22:49

我不这么认为。最好的选择是制作多个模板。话虽如此,我确信您可以编写一个扩展来执行此操作。

另一种方法是在模板中添加一个变量,您可以根据它所在的部分进行更改。

I don't think so. Your best bet would be to make multiple templates. That being said I'm sure you could write an extension that would do this.

Another way would be to add a variable in your template, that you change depending on which section it is in.

念三年u 2024-09-21 05:22:49

在同事的大力帮助下,答案如下。将其放入模板中(然后您可以从包含标题/指令/等文本的所有其他模板中调用该模板)。

<includeonly><css>
div.headingText { color: blue; border: 2px solid blue; background: lightcyan; width: 461px; padding:0.5em 0.5em 0.5em 0.5em; display: none; margin-bottom:-6px; }

h2 + div.headingText, h3 + div.headingText, h4 + div.headingText, h5 + div.headingText, h6 + div.headingText { display:block; margin-top:5px; }
</css>
<div class="headingText">'''{{{1|This [[tag]] applies only to this section.}}}'''</div></includeonly><noinclude>
your explanatory text
</noinclude>

注意:

  1. 这需要使用 CSS 扩展
  2. 实际上的作用是,如果标签直接包含在标题下方,则显示某些文本,否则不显示任何文本。 (本例中参数 1 中有默认文本,可以更改。)

With a lot of help from a colleague the answer is below. Put this into a template (which you then call from all your other templates containing header / instruction / etc. text).

<includeonly><css>
div.headingText { color: blue; border: 2px solid blue; background: lightcyan; width: 461px; padding:0.5em 0.5em 0.5em 0.5em; display: none; margin-bottom:-6px; }

h2 + div.headingText, h3 + div.headingText, h4 + div.headingText, h5 + div.headingText, h6 + div.headingText { display:block; margin-top:5px; }
</css>
<div class="headingText">'''{{{1|This [[tag]] applies only to this section.}}}'''</div></includeonly><noinclude>
your explanatory text
</noinclude>

Notes:

  1. This requires use of the CSS extension.
  2. What this actually does is show certain text if the tag is included directly below a title and no text otherwise. (It has default text in parameter 1 in this example, which can be changed.)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文