Help:Contributing/semanticDynamicContent: Difference between revisions
Semantic dynamic content: client parser functions + sitelinks (same-wiki repo+client, enabled Aug 19 2026) (via create-page on MediaWiki MCP Server) |
Correct #property vs #statements: same visible text, markup-level difference; drop wrong "values link to items" claim (via update-page on MediaWiki MCP Server) |
||
| Line 5: | Line 5: | ||
Both take a property — a P-number or its label — and render its statements. The difference is the output form: | Both take a property — a P-number or its label — and render its statements. The difference is the output form: | ||
| Function | Output | | | Function | Output form | Use it when | | ||
|----------|--------| | |----------|-------------|-------------| | ||
| <code>#statements</code> | | | <code>#statements</code> | Rich wikitext: each value keeps its markup (language attributes, list structure). | Default for page content — values stay marked up for styling and screen readers. | | ||
| <code>#property</code> | | | <code>#property</code> | Escaped plain text: no markup survives. | Inside templates or table cells, where markup would interfere. | | ||
Same | Same call, both forms — Q96 (quotation, one statement per language): | ||
{| class="wikitable" style="width:100%" | {| class="wikitable" style="width:100%" | ||
! | ! <code>#property</code> !! <code>#statements</code> | ||
|- | |- | ||
| {{#property:P2|from=Q96}} || {{#statements:P2|from=Q96}} | |||
| {{#property:P2|from=Q96}} | |||
| | |||
| {{#statements:P2|from=Q96}} | |||
|} | |} | ||
The visible text is identical. The difference is in the page source: <code>#statements</code> wraps each value in language markup, <code>#property</code> emits plain text. Item values render as labels, not links, on this wiki. | |||
== Examples == | == Examples == | ||
Revision as of 06:32, 20 August 2026
Semantic dynamic content renders item data on a wiki page at view time. Edit the item once; every page that renders its statements updates. The Wikibase client provides two parser functions; every example below is live against real items.
The two parser functions
Both take a property — a P-number or its label — and render its statements. The difference is the output form:
| Function | Output form | Use it when |
|----------|-------------|-------------|
| #statements | Rich wikitext: each value keeps its markup (language attributes, list structure). | Default for page content — values stay marked up for styling and screen readers. |
| #property | Escaped plain text: no markup survives. | Inside templates or table cells, where markup would interfere. |
Same call, both forms — Q96 (quotation, one statement per language):
#property |
#statements
|
|---|---|
| The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. | The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. |
The visible text is identical. The difference is in the page source: #statements wraps each value in language markup, #property emits plain text. Item values render as labels, not links, on this wiki.
Examples
Running example: Q99 (Factorial in Python). The from= argument names the entity; the property can be a P-number or a label.
| What you want | You type | You get |
|---|---|---|
| Instance | {{#statements:P1|from=Q99}}
|
code snippet |
| Programming language | {{#statements:P5|from=Q99}}
|
Python |
| Code source | {{#statements:P3|from=Q99}}
|
factorial = lambda n: 1 if n <= 1 else n * factorial(n - 1) |
| Attributed to | {{#statements:P6|from=Q99}}
|
Ada Lovelace |
| By label instead of P-number | {{#statements:instance of|from=Q99}}
|
code snippet |
| Another entity — Q55 (Markdown) | {{#statements:P1|from=Q55}}
|
programming language |
Sitelinks: pages ↔ items
A sitelink is a page title on the wikibase site stored on an item. It maps the page to the item; the item page then shows the link in its Sitelinks section. Without from=, a parser function uses the item sitelinked to the current page.
Live pairs on this wiki: Q55 (Markdown) ↔ Cheatsheets:Markdown, Q77 (SPARQL) ↔ Cheatsheets:SPARQL.
To link a page: open the item, add the page title in the Sitelinks section (site wikibase). Or use the API: action=wbsetsitelink with linksite=wikibase.
Gotchas
An item with no statements renders nothing — empty output is not an error. Q94 (Ada Lovelace) has no statements:
You type You get {{#statements:P1|from=Q94}}person
An unknown property is an explicit error, not empty output — P999 does not exist:
You type You get {{#statements:P999|from=Q55}}Failed to render property P999: P999 property not found.
Without
from=the page must be sitelinked to an item. This page is not linked, so{{#statements:P1}}on it renders nothing. Link the page to an item (see Sitelinks above) to use the short form.
Limits
Lua modules ({{#invoke:Wikibase}}) are not available — the Scribunto extension is not installed. Use the parser functions above.
See also
- Wikibase Client (official extension docs)
- Wikidata introduction — what a Wikibase is for
- Cheatsheets:SPARQL — query items the other way
- Help:Contributing — contributing to this wiki