Cargo/customizing tables

From Support Wiki
Jump to navigation Jump to search

This article explains how to add basic markup to a Cargo-generated table without resorting to using |format=template. Briefly, you use CONCAT with escaped wikitext as constant strings along with field names in a comma-separated list to achieve the output you want, and the escaped text will be parsed each line. If this makes sense to you, you can skip the rest of the page; if not then continue reading for a more in-depth explanation.

CONCAT

The basis of this procedure is the SQL function CONCAT. You can make the following (rather useless) query:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT("Kittens")
}}

Kittens, Kittens, Kittens, Kittens, Kittens

We could do a slightly more useful query like this:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT("Kittens")=Kittens,name
|limit=3
}}
Kittens name
Kittens Riften
Kittens Solitude
Kittens Whiterun

More...

We could also do the following:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT("Kittens ", name)=Kittens,_pageName
|limit=3
}}
Kittens _pageName
Kittens Riften Cargo/test data
Kittens Solitude Cargo/test data
Kittens Whiterun Cargo/test data

More...

And finally, here is a more practical example:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT("[[",_pageName,"{{!}}",name,"]]")=Link
|format=table
|limit=3
}}
Link

More...

So now you understand how CONCAT works.

Adding templates to CONCAT

Maybe we want to use {{Link}} instead of writing out CONCAT("[[",_pageName,"{{!}}",Name,"]]") every time. We can do the following:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT('{{((}}Link{{!}}',_pageName,'{{!}}display=',name,'{{))}}')=Link
|format=table
|limit=3
}}
Link

More...

What we're doing here is inserting the following text: {{Link|_pageName|display=Name}}, with the special characters in the constant text escaped, and the fields spaced in between. Obviously in this example, the resulting syntax line is less compact than spelling out the link, but this idea generalizes to any template you may want to use, to insert arbitrary markup into a table-format Cargo query. With this method, you can avoid storing any already-marked-up values, and still avoid |format=template in your final query!

Special case: adding line numbers

One special case of this is to use {{Iter}} with no parameters to add a line index:

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields=CONCAT("{{((}}Iter{{))}}")=N,_pageName,name
|format=table
|limit=3
}}
N _pageName name
1 Cargo/test data Riften
2 Cargo/test data Solitude
3 Cargo/test data Whiterun

More...

We can also simplify this with creation of a second template, {{IterField}} (this template also includes an automatic reset, so you can reuse the template on the same page without issues):

{{#cargo_query:tables=Cities
|where=isCapital="0"
|fields={{IterField}},_pageName,name
|format=table
|limit=3
}}
N _pageName name
1 Cargo/test data Riften
2 Cargo/test data Solitude
3 Cargo/test data Whiterun

More...

Required templates

Copy the following to your wiki: