有没有办法设置“新”参数,内部到模板或其他页面?

发布于 2025-01-11 04:39:04 字数 441 浏览 4 评论 0原文

假设我有一些页面可以采用两个参数 x 和 y。我经常发现自己在该页面中做一些事情,就像这个愚蠢的小例子一样:

{{#if: {{{x|{{{y|}}}}}} | '''{{{x|{{{y|}}}}}}'''. I repeat, {{{x|{{{y|}}}}}}.}}

在许多情况下,我非常希望简化 {{{x|{{{y|}}}}},为了清晰起见,方便打字,并且更难错过或搞砸。因此,我想做类似以下假设语法的操作:

{{#set:z|{{{x|{{{y|}}}}}}}}
{{#if: {{{z|}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}

也就是说,创建一个新参数 z,它传递到页面,但仍然可以在页面中使用。有没有办法做这样的事情?

Let's say I have some page which can take two parameters, x and y. I often find myself doing things in that page like in this silly little example:

{{#if: {{{x|{{{y|}}}}}} | '''{{{x|{{{y|}}}}}}'''. I repeat, {{{x|{{{y|}}}}}}.}}

In many cases, I would greatly prefer to simplify the reuse of {{{x|{{{y|}}}}}}, for clarity, for ease of typing, and for making it more difficult to miss or to screw up. So, I'd like to do something like the following hypothetical syntax:

{{#set:z|{{{x|{{{y|}}}}}}}}
{{#if: {{{z|}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}

That is, make a new parameter, z, which was not passed to the page, but nonetheless can be used in the page. Is there a way to do something like this?

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

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

发布评论

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

评论(1

翻了热茶 2025-01-18 04:39:04

有扩展 Variables,但它假设一定的解析顺序,这不会使用 Parsoid 解析页面时就是这种情况。

为了保证正确的解析顺序,您可以使用 Lua

但最简单的方法是创建一个新模板,仅采用一个参数并从原始模板中调用它。

模板1

{{template2| z = {{{x|{{{y|}}}}}} }}

模板2

{{#if: {{{z}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}

There is the extension Variables, but it assumes a certain order of parsing, which will not be the case when pages are parsed with Parsoid.

To guarantee the right order of parsing you can use Lua.

But the simplest way will be to create a new template, taking only one parameter and to call it from the original one.

Template1:

{{template2| z = {{{x|{{{y|}}}}}} }}

Template2:

{{#if: {{{z}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文