• Home
  • Random
  • Nearby
  • Log in
  • Settings
Donate Now If Wikipedia is useful to you, please give today.
  • About Wikipedia
  • Disclaimers
Wikipedia

Template:Table row counter

  • Template
  • Talk
  • Language
  • Watch
  • View source
Template documentation[view] [edit] [history] [purge]
Shortcut
  • {{TRCTemplate:TRC}}
This template uses Lua:
  • Module:Table row counter (sandbox)

This template counts the number of rows in wikitext tables. It does not work with nested tables, HTML tables, or tables contained in templates. It will also ignore <nowiki>...</nowiki> tags and <pre>...</pre> tags.

The template works by getting the wikitext source of a page and counting the number of tables in that source. This means that the template will not return the correct number of rows on preview, as it will still be using the old version of the page to count from. This also means that if there is more than one wikitext table on a page, you need to specify the number or the ID of the table manually.

Contents

  • 1 Redirects
  • 2 Usage
  • 3 Parameters
  • 4 Example with header cells
  • 5 Example without header cells
  • 6 See also

Redirects

  • {{TRC}}
  • {{trc}}

Usage

Table ID

{{table row counter|id=id}}

Table number

{{table row counter|tableno=number}}

All parameters

{{table row counter|id=id|tableno=number|ignore=number|page=pagename}}

Parameters

  • id - if specified, the template will decide which table to use by its ID. IDs can be assigned to wikitables by adding the text id="id" to the first line of the table (the same line as the {| code). IDs can consist only of uppercase letters, lowercase letters, and numbers. Blank spaces are not permitted. Dashes do not work (for example a date range of 2000-2017). The template is particular in that the ID in the first line of the table must have quotes around it: {| id="id" But the ID parameter in the template must NOT have quotes around it: {{table row counter|id=id}}
  • tableno - the number of the table to use, if there is more than one table on the page. Defaults to 1.
  • ignore - the number of rows to ignore. If specified, the template subtracts this number of rows from the count. This is useful if you do not need to count header rows at the top or bottom. Count rows, not lines of text within those rows.
  • page - the page to work on. Defaults to the current page.

Example with header cells

The table to be used

{| class="wikitable" id="foo"
!Column 1
!Column 2
|-
| Cell 1 || Cell 2
|-
| Cell 3 || Cell 4
|-
| Cell 5 || Cell 6
|}
Column 1 Column 2
Cell 1 Cell 2
Cell 3 Cell 4
Cell 5 Cell 6

Code and result

  • {{table row counter|id=foo|page=Template:Table row counter/doc}} → 3

Example without header cells

Note that the counter does not count the first row.

{| class="wikitable" id="foo2"
| Cell 1 || Cell 2
|-
| Cell 3 || Cell 4
|-
| Cell 5 || Cell 6
|}
Cell 1 Cell 2
Cell 3 Cell 4
Cell 5 Cell 6

Code and result

  • {{table row counter|id=foo2|page=Template:Table row counter/doc}} → 2
  • {{#expr: {{table row counter|id=foo2|page=Template:Table row counter/doc}} + 1 }} → 3

See also

  • Template:Static column begin - {{TRC}} is often used within that template.
The above documentation is transcluded from Template:Table row counter/doc. (edit | history)
Editors can experiment in this template's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this template.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Table_row_counter&oldid=1162411183"
Last edited on 29 June 2023, at 00:15

Languages

    • العربية
    • বাংলা
    • Català
    • Čeština
    • Dansk
    • 한국어
    • Հայերեն
    • Bahasa Indonesia
    • Kurdî
    • 日本語
    • ਪੰਜਾਬੀ
    • Português
    • Simple English
    • ไทย
    • Українська
    • اردو
    • 中文
    Wikipedia
    • Wikimedia Foundation
    • Powered by MediaWiki
    • This page was last edited on 29 June 2023, at 00:15 (UTC).
    • Content is available under CC BY-SA 4.0 unless otherwise noted.
    • Privacy policy
    • About Wikipedia
    • Disclaimers
    • Contact Wikipedia
    • Code of Conduct
    • Developers
    • Statistics
    • Cookie statement
    • Terms of Use
    • Desktop