Template:Diagram: Difference between revisions

Wrapper so diagrams can be inserted and repointed from the visual editor: the page name becomes a parameter rather than a parser-function target
 
Add style= parameter: per-embed Mermaid styling via <mermaid page=…>
Line 7: Line 7:


This template wraps the <code><nowiki>{{#display_diagram:}}</nowiki></code> parser function. The wrapper exists so the diagram name is a ''parameter'': the visual editor can insert and change parameters, but has no way to edit a parser function's target, so a bare <code><nowiki>{{#display_diagram:}}</nowiki></code> call can only be changed by editing the page source. Bare calls still work and still render — prefer this template for anything new.
This template wraps the <code><nowiki>{{#display_diagram:}}</nowiki></code> parser function. The wrapper exists so the diagram name is a ''parameter'': the visual editor can insert and change parameters, but has no way to edit a parser function's target, so a bare <code><nowiki>{{#display_diagram:}}</nowiki></code> call can only be changed by editing the page source. Bare calls still work and still render — prefer this template for anything new.
'''Per-embed styling (Mermaid only):''' <code><nowiki>{{Diagram|page=Mermaid:RE Microscope Workflow|style=style MW_Memory_File stroke-width:8px}}</nowiki></code> adds Mermaid statements to the end of the diagram for this embed only — the saved diagram and its other embeds are unchanged. Use the node's ''id'' (not its label), separate several statements with <code>;</code>. A misspelled id is not an error: Mermaid just draws an extra empty node. With <code>style</code> set, this template uses <code><nowiki><mermaid page="…"></nowiki></code> (defined in <code>LocalSettings.php</code>) instead of <code><nowiki>{{#display_diagram:}}</nowiki></code>; it does nothing for DOT, Drawio, BPMN or Gantt pages, which show an error instead.


The <code><nowiki>{{#if:}}</nowiki></code> guard below is load-bearing: <code>FDDisplayDiagram::run()</code> passes its argument to <code>Title::newFromText()</code> and calls <code>-&gt;exists()</code> on the result without a null check, so an empty <code>page</code> would throw a fatal error rather than render nothing.
The <code><nowiki>{{#if:}}</nowiki></code> guard below is load-bearing: <code>FDDisplayDiagram::run()</code> passes its argument to <code>Title::newFromText()</code> and calls <code>-&gt;exists()</code> on the result without a null check, so an empty <code>page</code> would throw a fatal error rather than render nothing.
Line 21: Line 23:
"required": true,
"required": true,
"suggested": true
"suggested": true
},
"style": {
"label": "Extra style (Mermaid only)",
"description": "Mermaid statements added to the end of the diagram for this embed only; the saved diagram page and its other embeds are unchanged. Use the node's id, not its label. Separate statements with ;",
"example": "style MW_Memory_File stroke-width:8px; style MW_Sample-Preparation fill:#ffd",
"type": "string"
}
}
},
},
"paramOrder": [
"paramOrder": [
"page"
"page",
"style"
],
],
"format": "inline"
"format": "inline"
}
}
</templatedata>
</templatedata>
</noinclude><includeonly>{{#if:{{{page|}}}|{{#display_diagram:{{{page|}}}}}|}}</includeonly>
</noinclude><includeonly>{{#if:{{{page|}}}|{{#if:{{{style|}}}|{{#tag:mermaid|{{{style|}}}|page={{{page|}}}}}|{{#display_diagram:{{{page|}}}}}}}|}}</includeonly>