Easiest way is wrapping it in a defined type.
define my_config() {
file { $name: ensure => file,
content => template(...),
}
}
Inside the template, you can use <%= @name %> or <%= @title %>, because
that is the name of the file being managed in this context.
Use the type like
my_config { [ "foo", "bar" ]: }
It is good practice to pass all non-fact non-hiera variables that are
relevant for the template as parameters to your defined type.
HTH,
Felix