打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

本站正在进行早期测试,目前仍存在许多内容的缺失。

模板:CSS/doc:修订间差异

来自星砂岛百科
Sizau留言 | 贡献
无编辑摘要
 
Sizau-bot留言 | 贡献
同步更新
 
(未显示1个用户的4个中间版本)
第1行: 第1行:
== Overview ==
== 概述 ==
The {{tl|CSS}} template is a helper utility used to load [https://www.mediawiki.org/wiki/Help:TemplateStyles TemplateStyles] (CSS) from a specific subpage.
'''CSS''' 用于在页面内按需加载 <code><nowiki>templatestyles</nowiki></code> 样式表,并确保同一路径只加载一次。默认拼接 <code><nowiki><namespace>:<name>/styles.css</nowiki></code>。


Unlike a direct {{#tag:templatestyles}} call, this template uses the [[mw:Extension:Variables|Variables extension]] to **deduplicate** style tags. If the same stylesheet is requested multiple times on a single page, it will only be output once, preventing the accumulation of redundant `<link rel="mw-deduplicated-inline-style">` tags in the HTML source.
== 用法 ==
 
最简调用:
== Usage ==
* {{tl|CSS}}
Insert this template at the top of a template or module page to load its associated `/styles.css` subpage.
 
{{tl|CSS|PageName|NamespaceID}}
 
* **1** (Optional): The base page name. Defaults to the current page name.
* **2** (Optional): The Namespace ID. Defaults to 10 (Template).
** 0: Main/Root
** 4: Project (Starsand Island Wiki)
** 10: Template
** 828: Module
 
== Technical Details ==
* **Deduplication Logic**: It defines a variable `ts_loaded_[path]` the first time a style is loaded. Subsequent calls to the same path are ignored.
* **Dependency**: Requires the [https://www.mediawiki.org/wiki/Extension:Variables Variables] extension to be installed on the Wiki.


== Examples ==
指定样式宿主页面:
=== Basic Usage ===
* {{tl|CSS|GiftsByNPC}}
To load styles from the current template's `/styles.css` subpage:
* {{tl|CSS}}


=== Specific Page ===
指定命名空间代码:
To load styles from a specific template:
* {{tl|CSS|GiftsByNPC|10}}
* {{tl|CSS|Infobox Item}}


=== Specific Namespace ===
== 示例 ==
To load styles for a module:
{{tl|CSS|GiftsByNPC}}
* {{tl|CSS|Common|828}} (Loads `Module:Common/styles.css`)


== TemplateData ==
== 模板数据 ==
<templatedata>
<templatedata>
{
{
  "description": "加载指定页面的 templatestyles 样式表,避免重复注入。",
   "params": {
   "params": {
     "1": {
     "1": {
       "label": "Page Name",
       "label": "样式宿主页面",
       "description": "The name of the page containing the /styles.css subpage. Defaults to the current page.",
       "description": "样式宿主页面名,默认使用当前页面全名(FULLPAGENAME)。",
       "type": "string",
       "type": "string",
       "suggested": true
       "required": false,
      "example": "GiftsByNPC"
     },
     },
     "2": {
     "2": {
       "label": "Namespace ID",
       "label": "命名空间代码",
       "description": "The ID of the namespace (e.g., 10 for Template, 828 for Module). Defaults to 10.",
       "description": "命名空间代码:828=Module, 4=Project, 0=主空间,其它/留空=Template。",
       "type": "number",
       "type": "string",
       "default": "10"
      "required": false,
       "example": "10"
     }
     }
   },
   },
  "description": "Loads TemplateStyles for a given page and namespace with automatic deduplication.",
   "format": "block"
   "format": "inline"
}
}
</templatedata>
</templatedata>


[[Category:Template documentation]]
== 说明 ==
* 会自动拼接为 <code><nowiki><namespace>:<name>/styles.css</nowiki></code>。
* 同一页面内重复调用不会重复插入样式。
* 内部使用 [[Module:Static]] 维护页面级加载标记。
 
[[分类:模板文档]]

2026年3月25日 (三) 17:50的最新版本

概述

CSS 用于在页面内按需加载 templatestyles 样式表,并确保同一路径只加载一次。默认拼接 <namespace>:<name>/styles.css

用法

最简调用:

指定样式宿主页面:

  • {{CSS|GiftsByNPC}}

指定命名空间代码:

  • {{CSS|GiftsByNPC|10}}

示例

{{CSS|GiftsByNPC}}

模板数据

加载指定页面的 templatestyles 样式表,避免重复注入。

模板参数

此模板首选参数换行的代码块格式。

参数描述类型状态
样式宿主页面1

样式宿主页面名,默认使用当前页面全名(FULLPAGENAME)。

示例值
GiftsByNPC
字符串可选
命名空间代码2

命名空间代码:828=Module, 4=Project, 0=主空间,其它/留空=Template。

示例值
10
字符串可选

说明

  • 会自动拼接为 <namespace>:<name>/styles.css
  • 同一页面内重复调用不会重复插入样式。
  • 内部使用 Module:Static 维护页面级加载标记。