双眼屈光不正是什么意思| 高光是什么意思| 合肥有什么玩的| 白醋泡脚有什么好处| 天外有天人外有人是什么意思| 球蛋白偏高是什么意思| 10月生日是什么星座| 吃什么改善睡眠| mophie是什么牌子| 美容美体包括什么项目| 榴莲不可以和什么一起吃| 抽象什么意思| 什么吃辣椒抓耳挠腮| 阿哥是什么意思| 梦见自己得了重病预示什么| 下午6点是什么时辰| 拔腋毛有什么危害| 文替是什么意思| 冷暖自知上一句是什么| 内热是什么原因引起的怎么调理| molly英文名什么意思| 素鸡是用什么做的| 做些什么| ab血型和o型生的孩子是什么血型| 舌头起泡吃什么药| 漫游什么意思| 这是什么| 聚乙二醇是什么| 15一16岁青少年腰疼是什么病| 为什么气血不足| 什么的季节| 吃阿胶对女人有什么好处| 腕管综合症吃什么药| 五味子有什么作用| 存款准备金率是什么意思| 打呼噜挂什么科| 书到用时方恨少下一句是什么| 牛筋草有什么功效| rush是什么意思| 疗养是什么意思| 皮炎吃什么药| 拉k是什么意思| 外阴痒是什么原因| 花甲不能和什么一起吃| 大便隐血弱阳性是什么意思| 心电图st段改变什么意思| 缺锌吃什么| 洗衣机不出水是什么原因| 身上泡疹是什么引起的| 什么是阴吹| 谷丙转氨酶是什么| 鱼刺卡喉咙挂什么科| 心率用什么字母表示| air是什么牌子| 人活着的意义是什么| 夹腿是什么| 赤是什么意思| 肚子怕冷是什么原因该怎么办| 受凉咳嗽吃什么药| 肝脏在人体的什么位置| 吃什么油对身体好| 生性凉薄是什么意思| 家里消毒杀菌用什么好| 心率低是什么原因| 甘耳朵旁什么字| gg了是什么意思| 三七甘一是什么意思| 麻腮风疫苗是预防什么| 蜈蚣进家有什么预兆| 郁闷什么意思| 五十八岁属什么生肖| 血压低什么原因造成的| 老师家访需要准备什么| 头晕视力模糊是什么原因| 冬虫夏草到底是什么| 奇花异草的异什么意思| 秋水长天什么意思| 脾虚湿盛吃什么药| 气血不足吃什么水果| 同房后小腹疼痛是什么原因| 沉默不是代表我的错是什么歌| 高密度脂蛋白胆固醇是什么意思| 鬼市是什么意思| 阳痿早泄吃什么药好| 水乳什么牌子好用| 高血糖能吃什么| 胃糜烂和胃溃疡有什么区别| 吵架是什么意思| 曹真和曹操什么关系| 早泄要吃什么药| 小河虾吃什么| 灵魂摆渡人是什么意思| 海龟汤是什么| 医助是什么工作| 吃什么可以补气血| 割包皮有什么影响| 甲减是一种什么病| 上午11点是什么时辰| 浙江大学什么专业最好| 孕妇查凝血是检查什么| 卡号是什么| 怀孕初期分泌物是什么样的| 生小孩有什么补贴政策| 什么是肾阳虚| 龙的幸运色是什么颜色| 病毒是什么| 洗葡萄用什么洗最干净| prr是什么意思| vte是什么| 血糖高吃什么食物最好最佳| 时迁的绰号是什么| 朱元璋是什么民族| 来月经为什么会拉肚子| 什么牌子的益生菌调理肠胃比较好| 指甲白色是什么原因| 卵泡是什么| 什么是蝴蝶宝宝| m1是什么单位| 守宫是什么动物| 抗坏血酸是什么| 入木三分什么意思| 发烧为什么感觉冷| 饺子是什么意思| 色弱什么意思| 看月经挂什么科| 结缡什么意思| 肺气肿吃什么食物好| 毒龙什么意思| 茶叶蛋用什么茶叶最好| 埋伏牙是什么意思| 刚出生的小鱼苗吃什么| 肚子疼应该吃什么药| 糖丸是什么疫苗| 七月二十五是什么星座| 大力丸是什么药| 吃什么长骨头最快| other是什么意思| 缺少雌激素吃什么可以补充| 外阴皮肤痒是什么原因| 现在执行死刑用什么方法| 女生的隐私长什么样子| 壁立千仞无欲则刚是什么意思| 1208是什么星座| 久坐睾丸疼是什么原因| 实时更新是什么意思| 星链是什么| pwp是什么意思| 左肺下叶纤维灶是什么意思| 暴饮暴食容易得什么病| 体检吃早餐有什么影响| 复方阿胶浆适合什么样的人喝| 淀粉酶是什么| xo兑什么饮料好喝| 神经鞘瘤挂什么科| 肾气不足有什么症状| 保妇康栓治疗什么妇科病| 鸡眼长什么样子| 吃什么东西可以补血| 牙齿咬不动东西是什么原因| 一本万利是什么意思| 福泽深厚什么意思| 八月三日是什么星座| 什么牙什么嘴| 脊髓是什么| 芭蕉和香蕉有什么区别| 迪赛尼斯属于什么档次| 小鸡啄米什么意思| 腰肌劳损用什么药| 尿路感染吃什么药| 治疗早泄吃什么药| 单侧耳鸣是什么原因引起的| 附件囊肿吃什么药最好| wba是什么意思| 肺结节是什么意思| 什么赴什么继| 白猫来家里有什么预兆| 自费是什么意思| 离线缓存是什么意思| 俄罗斯乌克兰为什么打仗| 十一月份什么星座| 血精和精囊炎吃什么药| 很能睡觉是什么原因| 什么方法睡觉快速入睡| 什么是鸡奸| 邪不压正什么意思| 胃属于什么科室| 血糖高初期有什么症状| 为什么支气管炎咳嗽长期不好| 血小板计数高是什么原因| 苹果什么时候成熟| sakose是什么牌子| 山的五行属什么| 八卦脸什么意思| 为什么突然得了荨麻疹| 水仙是什么茶| 两个百字念什么| 女性口臭都是什么原因| 左肾结石的症状是什么| 梦见烧纸钱是什么意思| 时来运转是什么意思| 眼睛发黄是什么原因引起的| 缺钾什么症状| 什么光| 双眼屈光不正是什么意思| 梦见杀羊是什么预兆| 做梦梦见火是什么意思| 体力不支是什么意思| 秦始皇的原名叫什么| 顿服是什么意思| 退行性改变是什么意思| 加百列是什么天使| 肝内点状钙化灶什么意思| 女人梦见掉头发是什么征兆| 长期喝咖啡有什么好处和坏处| Op是什么| 财代表什么生肖| 市监狱长是什么级别| 吃黑豆有什么好处和坏处| 女人什么时候最容易怀孕| 豌豆的什么不能吃| 吽是什么意思| 尿不尽吃什么药| 妙三多预防什么| 吃什么降血压| 柏拉图爱情是什么意思| 腔梗和脑梗有什么区别| 嘴巴周围长痘痘是什么原因引起的| 鱼的尾巴有什么作用| 每天吃洋葱有什么好处| 晚上吃什么不发胖| 鸡鸣寺求什么| 经常头疼是什么原因| 煲电话粥什么意思| 有过之而不及是什么意思| 什么是绘本| 总是心慌是什么原因| 梦见自己生了个儿子是什么意思| 梦见动物是什么意思| 脲是什么意思| 什么人不能吃狗肉| d二聚体高是什么原因| 三月份是什么星座的| 婴儿乳糖不耐受吃什么奶粉| 什么是毛囊炎| 穷是什么意思| 吃什么降羊水最快| 喉咙痛用什么药好得快| 做梦梦见屎是什么意思| 天降甘霖什么意思| 荨麻疹吃什么中药| 声音的高低叫什么| 睡眠不好吃什么药| 净身出户是什么意思| 心如刀割是什么意思| iva是什么意思| 为什么气血不足| 科伦是什么药| ol是什么| 胸痛是什么情况| 豆汁是什么味道| 女人抖腿代表什么意思| ppt是什么单位| 湛江有什么好吃的| 金达克宁和达克宁有什么区别| 百度

用车多么痛的领悟 致命的儿童盲区你注意过吗?

百度 与之前曝光的纽约热恋照不同的是,这组北京故事照讲述男女主角在花样般的年纪相遇,开启如梦似幻的少年之恋,在北京相恋,在纽约相守。

There are some advanced template coding techniques to improve the display or editing of templates in Wikipedia. There are also some tactics for debugging template parameters in the MediaWiki markup language. It is preferable that any templates requiring intricate control structures or conditional expressions be written in or converted to Lua modules because wikitext is not well-designed for this purpose.

Many bugs are associated with the difficulty in dealing with some awkward features in the markup language which lead to coding errors. Unbalanced metacharacters are a major source of errors. For example, coding {{1}}} instead of {{{1}}} causes it to act as if it were {{1}} }, thereby invoking Template:1 + "}".

There are some differences of wiki-formatting of contents of parameters when inside #if-expressions, but not when outside. Templates which need to be substituted need special handling. Providing parameter defaults or parameter aliases is covered as well.

Nesting levels limited to 40

edit

Inside a single template, the nesting limit is 40 nested expressions, such as 40 multiple "if-then-else-if...". At the 41st nested "if" keyword an error message might appear, as: "Exceeded nesting limit". However, when not nested beyond 40 levels, a template can contain hundreds of if-expressions and switch-branches, but not all nested inside the others.

Some templates have contained complex conditional calculations nested over 23 levels deep, for years. Also, some templates have contained hundreds of if-expressions, for years, just NOT all nested as one, giant: if-then-else-else-else-else-else....

MediaWiki wiki-formats the clauses inside #if

edit

An issue which complicates template processing, for parameters, is the wiki-formatting of parameter contents when inside of if-logic (such as #if or #ifeq) or #switch (or lc:, lcfirst:, uc:, ucfirst:). As of May 2012, the MediaWiki markup parser is still wiki-formatting the contents of parameters when inside #if-expressions (but not outside). This means that parameters containing spaces, lead semicolon, colon (":") or pound sign ("#") can change their values while inside the if-clauses (surprise!). So, for example, a parameter {{{4}}} when outside an #if can display differently than inside {{#ifeq:{{{1}}}=0|{{{4}}} ...}}. The worst shock is when parameter 4 contains a leading semicolon, which triggers formatting to become ye-olde bolded semicolon-header line:

TEST 1: {{#if:{{{4|}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 2: {{#if:{{{4|;}}}|{{{4|;}}} <== yes, semicolon|no, 4=empty}}
TEST 1: no, 4=empty
TEST 2:
<== yes, semicolon
<== Separate example of semicolon-header

The problem occurs whether inside of #if, #ifexpr, #ifeq or #switch markup expressions. If the parameter is preceded by text, in either of the then/else clauses, then the wiki-formatting inside the parameter does not occur.

TEST 3: {{#ifexpr:{{{1|7}}}=7|<b></b>{{{4|;}}} equals 7|not 7}}
TEST 4: {{#ifexpr:{{{1|7}}} < 9|{{{4|#}}} LESS THAN 9|not<9}}
TEST 5: {{#ifexpr:{{{1|7}}} < 9|&#32;{{{4|#}}} LESS THAN 9|not<9}}
TEST 6: "{{#ifexpr:{{{1|7}}} < 9|&#32;{{{4|#}}} LESS THAN 9|not<9}}"
TEST 3: ; equals 7
TEST 4:
  1. LESS THAN 9
TEST 5: # LESS THAN 9
TEST 6: " # LESS THAN 9"

In TEST 4, the leading pound sign "#" triggered auto-numbering of the line (indented with "1."). The situation of having a leading semicolon, colon or "#" might be relatively rare, but this is just a reminder: for showing the true contents of a template parameter, try to display a parameter outside the start of any if-statement clauses, or display other text before the parameter inside the if-logic, or else prepare for some shocking results when a parameter is wiki-formatted for display inside the if-logic.

If the result of #if, etc. is not intended to be formatted, using &#35;, &#58;, and &#59; instead of #, :, and ; will work fine.

TEST 7: {{#ifexpr:{{{1|7}}} < 9|{{{4|&amp;#35;}}} LESS THAN 9|not<9}}
TEST 7: # LESS THAN 9

Debugging

edit

Many coding errors can be debugged, more easily, by attempting to isolate the code section where coding errors most likely occurred. Intense proofreading, of the logic flow, is most often the quickest fix, such as checking for typical syntax errors (see below: "Common coding errors"). Sometimes, a section of troublesome code could be copied into a short test page, then by edit-preview, tested there, separately. However, if editing that extra-page window seems like too much effort, then consider merely copying the code to the top of the current template. Similarly, a template could be developed, in the early stages, as multiple sections of code, each to be debugged separately, then eventually joined together, such as nested sections with if-then-else-if.

As a review of those options, consider:

  • Try carefully proofreading troublesome code, matching "{{" with "}}". (consider using Equazcion's syntax highlighter for Notepad++)
  • Copy a template section into a test-page edit-window, for debug.
  • Copy a template section to the top of the template, for debug.
  • Restructure a template so that each section is more separated.

The basic strategy: isolate the code section to be debugged.

Next, the testing, of each section of code, is crucial. There are some age-old adages to heed:

  • If it hasn't been tested, then it doesn't work.
  • You can expect what you inspect. (W. Edwards Deming)

Perhaps put a variety of examples on each template's doc subpage, to help detect problems early in development. However, for complex templates, then the talk-page, or a special subpage "/testcases", should contain a section of numerous examples (a whole lot of them) to demonstrate the full scope of template features.

Defaulting parameters in expressions and if-logic

edit

When developing sections of markup that use template parameters, try to always set each parameter with a default value, especially inside expressions or if-logic coding:

  • {{#expr: 109.75 / {{{1|1}}} }} → default {1} as 1 not zero.
  • {{#ifeq: {{{answer|y}}}|y|show yes}}

If a particular parameter is given the same default value across the whole page, then that value could be easily changed, in a text editor, by a global search-and-replace string substitution, to change the default value to some other value, for testing each case.

If those parameters are not given default values, then those sections of code cannot be tested, during edit-preview, while editing the template. Any parameter without a default value will become the literal triple-brace text (such as the literal 7 characters: {{{x}}}), and non-defaulted parameters cannot be evaluated, in expressions or if-logic, during an edit-preview of the template page.

Common coding errors

edit

There are several common coding errors which will cause problems when processing templates. The following can be used as a checklist, to help debug problems, when a template seems to be acting bizarre:

  • Too few closing braces: A common problem is to put only 2 closing-braces around a parameter number or name, such as {{{1}}. Having only 2 closing-braces }} might treat the parameter as a template named "Template:1" (preceded by a lone "{" brace).
  • Unopened comments: Forgetting to insert <!-- at the start of an HTML comment can cause bizarre results, with no error message. Forgetting the exclamation point is very common: <-- should be <!--.
  • Unclosed comments: Forgetting to insert --> at the end of an HTML comment can cause bizarre results, with no error message.
  • Omitting colon or "#" on "#ifexpr": Forgetting to insert "#" or colon for "#ifexpr:" or "#expr:" can produce bizarre results, when passed into other subtemplates.
Omitting colon becomes literal text: {{#ifexpr {{{1|y}}}=0|then zero|else not}}

Note that those common coding errors could have been easily spotted by a simple syntax checker, such as warning that 3&2 braces could be trouble: {{{size|180px}} is treated as "{Template:Size" trying to pass 180px as the parameter because of only 2 end-braces.

Again, always checking first for common errors, as the first step, can avoid time hunting for "complex errors" which never really existed. Remember: the MediaWiki markup language is extremely error-prone, so that's why so many coding errors occur, and that's why:

Consider the above as a checklist to try first, as a type of sanity-check for the template.

Many hideous problems truly are merely 1-minute syntax fixes.

Coding a template to allow WP:SUBST substitution

edit

In rare cases, a template might need to be rewritten to allow text substitution (per WP:SUBST), where the results of running a template will be saved into the page during an edit-SAVE operation. In that case, the safesubst-prefix must be inserted into every markup function used inside that template, at every level of nested logic. Also, every HTML comment must be surrounded by "noinclude" tags: <noinclude><!--HTML comment HERE--></noinclude>.[a] Otherwise, all of the triggered HTML comments will be stored inside the SAVEd page, in the sequence executed by running the template. NOTE: All the extra "noinclude" and safesubst:<noinclude/> keywords will likely require the template's markup to be re-indented inside, to fit all that extra inserted text, which will widen and clutter the original markup style.

Specifically, to alter a template to allow text substitution, then the prefix safesubst:<noinclude/> must be inserted inside the opening double-brace {{ of each markup function inside that template. Some examples of inserting the safesubst-prefix inside a template's markup:

  • Total articles now: {{NUMBEROFARTICLES}} → 7,035,374
  • Total articles was: {{ subst:NUMBEROFARTICLES}} → 3,953,715
  • {{ safesubst:<noinclude/>#ifeq:{{{1|AX}}}|AX|yes}}
  • {{ safesubst:<noinclude/>lc:THIS LOWERCASE TEXT}} → this lowercase text

In general, every markup function which starts with double-brace {{ must be altered to insert the long safesubst-prefix safesubst:<noinclude/> (with no space afterward).[b] The action of keyword "safesubst" is to allow conditional substitution of markup, when the whole template is invoked as {{subst:MyTemplate|...}}. In essence, the keyword "safesubst" could be called "ifsubst" as meaning, "if 'subst:' was used to invoke this template, then substitute here as well".

Remember: The safesubst-prefix must be inserted into every markup function inside that template, except for test logic never used in an actual page. Any markup which omits "safesubst" will fail if the template is executed by the subst mode, "{{subst:MyTemplate|...}}". Parameters are not changed, so {{{1}}} would remain unchanged, without a safesubst-prefix.

Exceptions: Only logic which would never be stored in a page could omit "safesubst", such as test-logic which is triggered by special parameter values never used inside a stored page. Any markup which omits "safesubst" will only work during regular transclusion but fail if the template is executed by using the subst-mode prefix "subst:". For more examples, and further technical explanations, see: WP:Substitution.

Indenting the long lines: All of the added safesubst-prefix text will widen lines, so to improve readability, they could be split and indented before any of the safesubst:<noinclude/> prefixes. For example:

  • {{ safesubst:<noinclude/>#ifeq:{{
           safesubst:<noinclude/>padleft:|1|{{{1}}} }}|A|Begins with "A"}}

In that indentation style, the text "safesubst:<noinclude/>" begins the next line. Avoid wrapping a line after the prefix safesubst:<noinclude/> because several markup functions might fail to work correctly unless the safesubst prefix is immediately attached before the keyword, such as {{&nbsp;safesubst:<noinclude/>#ifeq:...}}

Examples of very large templates

edit

When trying to perform more-complex, or intricate, operations, there might be an instinctive fear that templates cannot be as large as needed. However, there are many very large templates which have been running, for years, on Wikipedia, for example:

The source-footnote formatter, Template:Citation/core, displays a standardized citation format, as invoked by several wrapper templates which pass hundreds of parameters, where the core logic checks 621 parameter values, in the conditional markup expressions.

Try some programming

edit

The Special:ExpandTemplates page takes some wikitext and expands everything in double braces recursively: templates, parser functions like {{#if:...}}, and variables like {{CURRENTDAY}}

See also

edit

Notes

edit
  1. ^ But if you want the HTML comment to appear, as is the case, for example, with User warning templates, then do not enclose the HTML comment in <noinclude> tags.
  2. ^ If you are familiar with regular expressions, you can do this like this:
    • Search for pattern ([^{]){{([^{]) and replace it with \1{{ safesubst:<noinclude/>\2
    Or, in one step, for one style of regex :
    • s/([^{]){{([^{])/\1{{ safesubst:<noinclude/>\2/g
    You might need to break up long lines; see "Indenting the long lines" in this section. As a practical matter, it's easier to join lines of code than to break them, so if you replace the blank in the replace-pattern above with a newline (plus optional white space) instead, it will break lines with every substitution; when it's done, just go back and join any lines that are too short.


dtc是什么意思 为什么要长智齿 斐然是什么意思 令人唏嘘是什么意思 胃里有胀气吃什么药
黑豆不能和什么一起吃 言外之意是什么意思 屁多肚子胀是什么原因 黄精是什么东西 贴切是什么意思
否认是什么意思 马步鱼是什么鱼 九月是什么星座的 原图是什么意思 做梦梦见僵尸是什么预兆
尿有泡沫是什么原因 运动不出汗是什么原因 口舌生疮吃什么药最见效 手指麻木吃什么药 什么在千里
手机有什么品牌hcv9jop1ns3r.cn 阔绰什么意思hcv9jop0ns6r.cn 开水冲鸡蛋有什么好处hcv9jop0ns7r.cn 100001是什么电话hcv9jop8ns2r.cn 栀子花什么时候开花hcv9jop8ns3r.cn
阴历七月是什么星座hcv8jop7ns3r.cn 关节疼痛吃什么药hcv8jop1ns4r.cn 孝顺的真正含义是什么hcv7jop6ns7r.cn 贤上腺瘤是什么意思hcv8jop2ns9r.cn 出家人是什么意思chuanglingweilai.com
忠于自己是什么意思hcv9jop6ns0r.cn 书店买不到的书是什么书bjhyzcsm.com 右边脑袋疼是什么原因hcv8jop9ns8r.cn 月经推迟量少是什么原因hcv8jop7ns2r.cn ygk是什么牌子dajiketang.com
什么品牌油烟机好0297y7.com 做牛排用什么部位的牛肉hcv8jop5ns3r.cn 什么叫哮喘hcv8jop0ns0r.cn 乙肝五项一五阳性什么意思jasonfriends.com 孕囊小是什么原因hcv8jop4ns3r.cn
百度