Template:Recipe: Difference between revisions

From Against the Storm Official Wiki
Connecting to the new template modules that are easier to maintain
Revised the documentation, now includes how to use the ingredient parameter
Line 6: Line 6:
</includeonly><noinclude>
</includeonly><noinclude>


Generates recipe tables. Use this wherever you need to show how to use [[Resources|Goods]] or [[Buildings]].


<code><nowiki>{{#invoke: Recipe|render
== Overview ==
| product= {{{ 1|{{{product|}}} }}}
Create a concise, sortable table using game data to show in-game recipes. The table mimics the layout of the in-game recipe browser, with the building, efficiency of the recipe, number of ingredients, and the product.
| building={{{ 2|{{{building|}}} }}}
| ingredient={{{ingredient|}}}
}}</nowiki></code>


== Parameters ==


This template is used like this:
At least one of these is required. Depending on which parameters you provide, the table may ignore other parameters. If the names provided are not spelled correctly (including punctuation), matching their in-game names, the recipe will return an error.
<code><nowiki>{{Recipe|product|building|ingredient}}</nowiki></code>


{| class="wikitable"
! Parameter !! Type !! Description
|-
| product || string || The name of the product associated with the recipe. Can be used in conjunction with <code>building</code> to display exactly one recipe.
|-
| building || string || The name of the building where the recipe is produced. Can be used in conjunction with <code>product</code> to display exactly one recipe.
|-
| ingredient || string || The name of an ingredient in a recipe. If you provide this parameter, the template does '''not''' filter the results further, but ignores the other parameters and returns a long table of all recipes where the ingredient could be used.
|}


This template calls <code>renderRecipe</code> in '''Module:RenderRecipe''' to get recipes for a product and/or a building. This will generate a new wikitable full of content from the game: buildings, stars of efficiency, ingredients, and products.
== Errors ==


This template standardizes the display of recipes throughout this wiki and greatly simplifies the amount of writing that is necessary when adding new content pages, especially for resources and buildings.
When a product, building, or ingredient is not spelled correctly or is not a valid name, the template returns an error message to help you locate the spelling or name mistake.


'''Example:'''


== Usage ==
Broken: <code><nowiki>{{Recipe|building=BrickOven}}</nowiki></code>


Giving the template both a product and a building will result in a table with exactly one recipe. Giving the template either a product or a building will result in a table with (usually) more than one row. If nothing is provided, an error will appear identifying the expectation.
{{Recipe|building=BrickOven}}


Here are ways to call the template, as they would be written in the article calling the template:
Fixed: <code><nowiki>{{Recipe|building=Brick Oven}}</nowiki></code>


{| class="wikitable"
{{Recipe|building=Brick Oven}}
 
There may be cases where the name you should use to look up a good or building is not the right name. Please post these to this template's discussion page.
 
== Examples ==
 
=== Basic Usage for Products and Buildings ===
 
A standard use of the template to show exactly one recipe for a product, in one building:
 
<pre>{{Recipe|Crystalized Dew|Brickyard}}</pre>
 
Yields:
 
{{Recipe|Crystalized Dew|Brickyard}}
 
Here are several ways to call the template for products and buildings.
 
{| class="wikitable mw-collapsible"
! Argument !! Examples !! Expected outcome
! Argument !! Examples !! Expected outcome
|-
|-
| None
| no parameters || <code><nowiki>{{Recipe}}</nowiki></code> || an error
| <code><nowiki>{{Recipe}}</nowiki></code>
| An error
|-
|-
| Product and building
| product and building
| style="white-space: nowrap" | <code><nowiki>{{Recipe|Crystalized Dew|Brickyard}}</nowiki></code> <br> <code><nowiki>{{Recipe|product=Crystalized Dew|building=Brickyard}}</nowiki></code>
|style="white-space: nowrap"| <code><nowiki>{{Recipe|Crystalized Dew|Brickyard}}</nowiki></code> <br> <code><nowiki>{{Recipe|product=Crystalized Dew|building=Brickyard}}</nowiki></code>
| A table with one row.
| A table with exactly one row.
|-
|-
| Product only
| product only
| style="white-space: nowrap" | <code><nowiki>{{Recipe|Pie}}</nowiki></code> <br> <code><nowiki>{{Recipe|product=Pie}}</nowiki></code>
|style="white-space: nowrap"| <code><nowiki>{{Recipe|Pie}}</nowiki></code> <br> <code><nowiki>{{Recipe|product=Pie}}</nowiki></code>
| A table with several rows, one for each building in which '''Pie''' can be produced.
| A table with several rows, one for each building in which '''Pie''' can be produced.
|-
|-
| Building only
| building only
| style="white-space: nowrap" | <code><nowiki>{{Recipe||Scribe}}</nowiki></code> ''(note the double pipe)'' <br> <code><nowiki>{{Recipe|building=Scribe}}</nowiki></code>
|style="white-space: nowrap"| <code><nowiki>{{Recipe||Scribe}}</nowiki></code> ''(note the double pipe)'' <br> <code><nowiki>{{Recipe|building=Scribe}}</nowiki></code>
| A table with several rows, one for each product that can be produced in the '''Scribe.'''
| A table with several rows, one for each product that can be produced in the '''Scribe.'''
|}
|}


=== Ingredients ===
Unlike when specifying the product and/or building, when you specify the <code>ingredient</code>, you explicitly must name the parameter (with <code>ingredient=</code>...). When you do so, the template ignores the other parameters you may have provided. This can be confusing if, for example, you are looking for all of the recipes in the Brick Oven that use Herbs—this is not possible at this time. This may be fixed in the future if there are sufficient needs for further filtering.
The results of specifying the ingredient can be a long table. But on a resource's page, this information is expected to be valuable.
<pre>{{Recipe|ingredient=Wine}}</pre>
<pre>{{Recipe|building=Lumber Mill|ingredient=Wine}}</pre>
Both result in:
{{Recipe|ingredient=Wine}}
=== Further Examples and Errors ===


== Examples ==
The following are generated by calling the template as shown in the parameter examples table above.


The following are generated by calling the template, as shown in the examples in the table above.
1. product and building:


<pre>{{Recipe|Crystalized Dew|Brickyard}}</pre>


1. <code><nowiki>{{Recipe|Crystalized Dew|Brickyard}}</nowiki></code> yields:
Yields:


{{Recipe|Crystalized Dew|Brickyard}}
{{Recipe|Crystalized Dew|Brickyard}}


2. product only
<pre>{{Recipe|Pie}}</pre>


2. <code><nowiki>{{Recipe|Pie}}</nowiki></code> yields:
Yields:


{{Recipe|Pie}}
{{Recipe|Pie}}


3. building only


3. <code><nowiki>{{Recipe||Scribe}}</nowiki></code> yields:
<pre>{{Recipe|building=Scribe}}</pre>


{{Recipe||Scribe}}
Yields:


{{Recipe|building=Scribe}}


The following are error states generated by calling the template incorrectly.
The following are error states generated by calling the template incorrectly.


4. with no parameters


4. With no arguments, <code><nowiki>{{Recipe}}</nowiki></code> yields:
<pre>{{Recipe}}</pre>


'''{{Recipe}}'''
Yields:


{{Recipe}}


5. Skipping the double pipe AND not specifying that the provided name is the building in <code><nowiki>{{Recipe|Scribe}}</nowiki></code> yields:
5. using only one pipe and not specifying that the provided name is the building


'''{{Recipe|Scribe}}'''
<pre>{{Recipe|Scribe}}</pre>


Yields:


6. Mixing naming the arguments and not naming the arguments <code><nowiki>{{Recipe|product=Eggs|Ranch}}</nowiki></code> yields:
{{Recipe|Scribe}}


'''{{Recipe|product=Eggs|Ranch}}'''
6. asking for products or buildings with no recipes


<pre>{{Recipe|Market}}</pre>


7. Specifying products or buildings with no recipes <code><nowiki>{{Recipe|Market}}</nowiki></code> yields:
Yields:


'''{{Recipe|building=Market}}'''</noinclude>
{{Recipe|building=Market}}
</noinclude>

Revision as of 03:37, 6 November 2023


Generates recipe tables. Use this wherever you need to show how to use Goods or Buildings.

Overview

Create a concise, sortable table using game data to show in-game recipes. The table mimics the layout of the in-game recipe browser, with the building, efficiency of the recipe, number of ingredients, and the product.

Parameters

At least one of these is required. Depending on which parameters you provide, the table may ignore other parameters. If the names provided are not spelled correctly (including punctuation), matching their in-game names, the recipe will return an error.

Parameter Type Description
product string The name of the product associated with the recipe. Can be used in conjunction with building to display exactly one recipe.
building string The name of the building where the recipe is produced. Can be used in conjunction with product to display exactly one recipe.
ingredient string The name of an ingredient in a recipe. If you provide this parameter, the template does not filter the results further, but ignores the other parameters and returns a long table of all recipes where the ingredient could be used.

Errors

When a product, building, or ingredient is not spelled correctly or is not a valid name, the template returns an error message to help you locate the spelling or name mistake.

Example:

Broken: {{Recipe|building=BrickOven}}

Script error: The function "render" does not exist.


Fixed: {{Recipe|building=Brick Oven}}

Script error: The function "render" does not exist.


There may be cases where the name you should use to look up a good or building is not the right name. Please post these to this template's discussion page.

Examples

Basic Usage for Products and Buildings

A standard use of the template to show exactly one recipe for a product, in one building:

{{Recipe|Crystalized Dew|Brickyard}}

Yields:

Script error: The function "render" does not exist.


Here are several ways to call the template for products and buildings.

Argument Examples Expected outcome
no parameters {{Recipe}} an error
product and building {{Recipe|Crystalized Dew|Brickyard}}
{{Recipe|product=Crystalized Dew|building=Brickyard}}
A table with exactly one row.
product only {{Recipe|Pie}}
{{Recipe|product=Pie}}
A table with several rows, one for each building in which Pie can be produced.
building only {{Recipe||Scribe}} (note the double pipe)
{{Recipe|building=Scribe}}
A table with several rows, one for each product that can be produced in the Scribe.

Ingredients

Unlike when specifying the product and/or building, when you specify the ingredient, you explicitly must name the parameter (with ingredient=...). When you do so, the template ignores the other parameters you may have provided. This can be confusing if, for example, you are looking for all of the recipes in the Brick Oven that use Herbs—this is not possible at this time. This may be fixed in the future if there are sufficient needs for further filtering.

The results of specifying the ingredient can be a long table. But on a resource's page, this information is expected to be valuable.

{{Recipe|ingredient=Wine}}
{{Recipe|building=Lumber Mill|ingredient=Wine}}

Both result in:

Script error: The function "render" does not exist.


Further Examples and Errors

The following are generated by calling the template as shown in the parameter examples table above.

1. product and building:

{{Recipe|Crystalized Dew|Brickyard}}

Yields:

Script error: The function "render" does not exist.


2. product only

{{Recipe|Pie}}

Yields:

Script error: The function "render" does not exist.


3. building only

{{Recipe|building=Scribe}}

Yields:

Script error: The function "render" does not exist.


The following are error states generated by calling the template incorrectly.

4. with no parameters

{{Recipe}}

Yields:

Script error: The function "render" does not exist.


5. using only one pipe and not specifying that the provided name is the building

{{Recipe|Scribe}}

Yields:

Script error: The function "render" does not exist.


6. asking for products or buildings with no recipes

{{Recipe|Market}}

Yields:

Script error: The function "render" does not exist.