Help:Cargo: Difference between revisions

Line 4: Line 4:


==Storing data with Cargo==
==Storing data with Cargo==
Storing data is done using the <code><nowiki>{{#cargo_store}}</nowiki></code> parser function within a template. This template also needs to either declare the cargo table it will store content into, or attach itself to a cargo table that's defined in another template. For example, {{temp|BTD6 upgrade info}} is an infobox template that both defines the <code>btd6_upgrades</code> cargo table and stores the info for all those upgrades using template parameters.
Unlike a wikitext table, it is not possible for any user (even admins) to "edit" a Cargo table in the traditional sense. The only way to store data in a Cargo table is by using the <code><nowiki>{{#cargo_store}}</nowiki></code> parser function within a template (or a Lua module). This means adding, removing, or changing values in a table requires editing a template call on a page. For example, in order to change the cost of the "Perma-Spike" upgrade in the <code>btd6_upgrades</code> table, one needs to edit the <code>cost</code> parameter in the <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> template call on the [[Perma-Spike (BTD6)]] page, because the <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> template call on that page is what stores the information about that upgrade to the Cargo table.
 
A template also needs to either declare the cargo table it will store content into, or attach itself to a cargo table that's defined in another template. For example, <code><nowiki>{{BTD6 upgrade info}}</nowiki></code> is an infobox template that both declares the <code>btd6_upgrades</code> cargo table and stores the info for all those upgrades using template parameters.


There are two major steps to setting up a cargo table: declaring the table and storing content in the table. This guide assumes you already know [[Help:Templates|how to create templates]].
There are two major steps to setting up a cargo table: declaring the table and storing content in the table. This guide assumes you already know [[Help:Templates|how to create templates]].