fetch static method

Future<Template> fetch({
  1. required String url,
  2. Map<String, String?>? parameters,
  3. required bool refresh,
})

Implementation

static Future<Template> fetch({required String url, Map<String, String?>? parameters, required bool refresh}) async
{
  Log().debug('Building template');

  // get the template
  XmlDocument? document = await fetchTemplate(url: url, refresh: refresh);

  // deserialize
  if (document != null) return Template.fromDocument(name: url, xml: document, parameters: parameters);

  // not found - build error template
  String xml404 = errorTemplate('Page Not Found', null, url);

  // parse the error template created
  try
  {
    document = XmlDocument.parse(xml404);
  }
  on  Exception catch(e)
  {
    xml404 = errorTemplate('Error on Page', url, e.toString());
    document = Xml.tryParse(xml404);
  }

  // return the error template
  return Template.fromDocument(name: url, xml: document, parameters: parameters);
}