aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/mdn/structures/macros/index.html
blob: 8a8f1eea2f3f2e80c471457c8ac623c0aeae9c2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
title: Macros
slug: MDN/Structures/Macros
translation_of: MDN/Structures/Macros
---
<div>{{MDNSidebar}}</div>

<p><span class="seoSummary">The <a href="/en-US/docs/Project:MDN/Kuma" title="/en-US/docs/Project:MDN/Kuma">Kuma</a> platform on which MDN runs provides a powerful macro system, <a href="/en-US/docs/MDN/Contribute/Tools/KumaScript" title="/en-US/docs/Project:MDN/Kuma/KumaScript_guide">KumaScript</a>, which makes it possible to do a wide variety of things automatically. This article provides information on how to invoke MDN's macros within articles.</span></p>

<p>The <a href="/en-US/docs/MDN/Contribute/Tools/KumaScript" title="/en-US/docs/Project:MDN/Kuma/KumaScript_guide">KumaScript guide</a> provides an in-depth look at how to use macros on MDN, so this section is more of a brief overview.</p>

<h2 id="Como_as_macros_são_implementadas">Como as macros são implementadas</h2>

<p>Macros on MDN are implemented using server-executed <a href="/en-US/docs/Web/JavaScript" title="/en-US/docs/Web/JavaScript">JavaScript</a> code, interpreted using <a href="https://nodejs.org/en/" title="https://nodejs.org/en/">Node.js</a>. On top of that we have a number of libraries we've implemented that provide wiki-oriented services and features to let macros interact with the wiki platform and its contents. If you're interested in learning more, see the <a href="/en-US/docs/MDN/Contribute/Tools/KumaScript" title="/en-US/docs/Project:MDN/Kuma/KumaScript_guide">KumaScript guide</a>.</p>

<h2 id="Using_a_macro_in_content">Using a macro in content</h2>

<p>To actually use a macro, you simply enclose the call to the macro in a pair of double-braces, with its parameters, if any, enclosed in parentheses; that is:</p>

<pre class="notranslate">\{{macroname(parameter-list)}}</pre>

<p>A few notes about macro calls:</p>

<ul>
 <li>Macro names are case-sensitive, but some attempt is made to correct for common capitalization errors; you may use all lowercase even if the macro name uses caps within it, and you may capitalize a macro whose name normally starts with a lower-case letter.</li>
 <li>Parameters are separated by commas.</li>
 <li>If there are no parameters, you may leave out the parentheses entirely; <code>\{{macroname()}}</code> and <code>\{{macroname}}</code> are identical.</li>
 <li>Numeric parameters can be in quotes, or not. It's up to you (however, if you have a version number with multiple decimals in it, it needs to be in quotes).</li>
 <li>If you get errors, review your code carefully. If you still can't figure out what's going on, see <a href="/en-US/docs/MDN/Kuma/Troubleshooting_KumaScript_errors">Troubleshooting KumaScript errors</a> for help.</li>
</ul>

<p>Macros are heavily cached; for any set of input values (both parameters and environmental values such as the URL for which the macro was run), the results are stored and reused. This means that the macro is only actually run when the inputs change.</p>

<div class="note">
<p><strong>Note:</strong> You can force all the macros on a page to be re-evaluated by force-refreshing the page in your browser (that is, a shift-reload).</p>
</div>

<p>Macros can be as simple as just inserting a larger block of text or swapping in contents from another part of MDN, or as complex as building an entire index of content by searching through parts of the site, styling the output, and adding links.</p>

<p>You can read up on our most commonly-used macros on the <a href="/en-US/docs/MDN/Contribute/Structures/Macros/Commonly-used_macros" title="/en-US/docs/Project:MDN/Contributing/Custom_macros">Commonly-used macros</a> page; also, there's a <a href="https://developer.mozilla.org/en-US/docs/templates" title="https://developer.mozilla.org/en-US/docs/templates">complete list of all macros</a> here. Most macros have documentation built into them, as comments at the top.</p>