Struct parsoid::prelude::Template [−][src]
pub struct Template { /* fields omitted */ }
Expand description
Represents a MediaWiki template ({{foo}}
)
How to access values from an existing template:
let code = client.transform_to_html("{{1x|test}}").await?;
// 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.get_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", ¶ms)?;
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
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
Auto Trait Implementations
impl !RefUnwindSafe for Template
impl !UnwindSafe for Template
Blanket Implementations
Mutably borrows from an owned value. Read more
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