【问题标题】:Pass a multiline text block as MediaWiki template parameter将多行文本块作为 MediaWiki 模板参数传递
【发布时间】:2013-10-23 09:29:10
【问题描述】:

我希望制作一个折叠模板来隐藏一段文本并通过单击展开来显示它。 我发现这样的代码如下

<div class="mw-collapsible mw-collapsed" style="background-color: #E6E6E6; border-style: thin black; font-style:italic; ">
<p><i>Try it by yourself before expanding on the right!</i></p>
<div class="mw-collapsible-content">
some text or wiki encoded text content (better for formatings and images)
that will remain hidden
until expand is clicked
</div>
</div>

我尝试为(折叠)制作模板

<div class="mw-collapsible mw-collapsed" style="background-color: #E6E6E6; border-style: thin black; font-style:italic; ">
<p><i>Try it by yourself before expanding on the right!</i></p>
<div class="mw-collapsible-content">
{{{1}}}
</div>
</div>

我目前失败的电话是

{{Collapse|some text or wiki encoded text content (better for formatings and images)
    that will remain hidden
    until expand is clicked}}

但我没有成功使用 {{{1}}} 传递输入文本块,因为我的内容充满了换行符和其他格式标记。

我是否需要在模板中或在调用 wrap 以及使用哪个标签中进行操作? 欢迎任何帮助。

【问题讨论】:

  • “但我没有成功” 到底发生了什么?实际结果如何,与预期结果有何不同?

标签: templates parameters mediawiki


【解决方案1】:

您需要创建两个模板:

{{Collapse Begin}}

有内容:

<div class="mw-collapsible mw-collapsed" style="background-color: #E6E6E6; border-style: thin black; font-style:italic; ">
<p><i>Try it by yourself before expanding on the right!</i></p>
<div class="mw-collapsible-content">

还有:

{{Collapse End}}

有内容:

</div>
</div>

然后在页面上添加:

{{Collapse Begin}}
some text or wiki encoded text content (better for formatings and images)
that will remain hidden
until expand is clicked
{{Collapse End}}

【讨论】:

    【解决方案2】:

    显然,命名参数允许使用多行输入(不要问我为什么!)。

    以下代码为我完成了这项工作,但感谢 ankap 的聪明想法,我将在其他地方重用它。

    当在列表中使用时,我添加了一个可选的边距来缩进彩色框,并为折叠模式中显示的消息添加了一个单独的参数。

    <!-- takes tup to three parameters
    * margin: to indent the block in the page, useful if the collapse is within a bullet list
    * comment: to show a warning on the expand line
    * content: the actual content to hide
    # adding additional div improved support for lists etc...
    -->
    <div class="mw-collapsible mw-collapsed" style="background-color: #E6E6E6; 
    border-style: thin black; font-style:italic; margin-left: {{{margin|0px}}}; ">
    <includeonly><i>{{{comment|<nowiki>
    Try it by yourself before expanding on the right!</nowiki>}}}</i><includeonly>
    <div class="mw-collapsible-content"><div>{{{content|{{{1}}}}}}</div></div>
    </div>
    

    享受吧!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      相关资源
      最近更新 更多