Community Central
Community Central

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=Extensions
|where=IsOurs="1"
|fields=CONCAT("Kittens")
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("Kittens") }}

We could do a slightly more useful query like this:

{{#cargo_query:tables=Extensions
|where=IsOurs="1"
|fields=CONCAT("Kittens")=Kittens,Name
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("Kittens")=Kittens,Name |limit=3 }}

We could also do the following:

{{#cargo_query:tables=Extensions
|where=IsOurs="1"
|fields=CONCAT("Kittens ", Name)=Kittens,_pageName
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("Kittens ", Name)=Kittens,_pageName |limit=3 }}

And finally, here is a more practical example:

{{#cargo_query:tables=Extensions
|where=IsOurs="1"
|fields=CONCAT("[[",_pageName,"{{!}}",Name,"]]")=Link
|format=table
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("",Name,"")=Link |format=table |limit=3 }}

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=Extensions
|where=IsOurs="1"
|fields=CONCAT('{{((}}Link{{!}}',_pageName,'{{!}}display=',Name,'{{))}}')=Link
|format=table
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT('{{Link|',_pageName,'|display=',Name,'}}')=Link |format=table |limit=3 }}

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=Extensions
|where=IsOurs="1"
|fields=CONCAT("{{((}}Iter{{))}}")=N,_pageName,Name
|format=table
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("{{Iter}}")=N,_pageName,Name |format=table |limit=3 }}

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=Extensions
|where=IsOurs="1"
|fields={{IterField}},_pageName,Name
|format=table
|limit=3
}}

{{#cargo_query:tables=Extensions |where=IsOurs="1" |fields=CONCAT("{{Iter}}")=N,_pageName,Name |format=table |limit=3 }}

Required templates[]

Copy the following to your wiki: