pub struct Template { /* private fields */ }
Expand description

Represents a MediaWiki template ({{foo}})

How to access values from an existing template:

let code = client.transform_to_html("{{1x|test}}").await?.into_mutable();
// Get the `Template` instance
let template = code.filter_templates()?[0].clone();
assert_eq!(template.name(), "Template:1x".to_string());
assert_eq!(template.raw_name(), "./Template:1x".to_string());
assert_eq!(template.name_in_wikitext(), "1x".to_string());
assert_eq!(template.param("1"), Some("test".to_string()));

How to create and insert a new template:

let mut params = map::IndexMap::new();
params.insert("1".to_string(), "test".to_string());
let template = Template::new("1x", &params)?;
let code = Wikicode::new("");
code.append(&template);
let wikitext = client.transform_to_wikitext(&code).await?;
assert_eq!(wikitext, "{{1x|test}}".to_string());

You can also use Template::new_simple() if there are no parameters to pass.

Implementations

Create a new template with no parameters

Create a new template

Get the name of the template as it appears in wikitext

Get the full name of the template, e.g. ./Template:Foo_bar or the parser function, e.g. ifeq.

Get a pretty normalized name of a template, e.g. Template:Foo bar or the parser function, e.g. ifeq

Get a map of all parameters, named and unnamed

Get the wikitext value of a specific parameter if it exists

Get the name of the parameter as it appears in the wikitext. For example given {{1x|param<!--comment-->name=value}} looking up paramname would return Some("param<!--comment->name").

Whether it’s a template (as opposed to a parser function)

Whether it’s a parser function (as opposed to a template)

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Remove this from the document

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more