public static Template Import(XmlNode n, User u) { string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("Alias")); Template t = Template.GetByAlias(alias); if (t == null) { t = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("Name")), u); } t.Alias = alias; t.ImportDesign(xmlHelper.GetNodeValue(n.SelectSingleNode("Design"))); return(t); }
/// <summary> /// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>. /// </summary> /// <param name="docRequest">The <c>PublishedContentRequest</c>.</param> /// <returns>A value indicating whether an Umbraco document was found and assigned.</returns> /// <remarks>If successful, also assigns the template.</remarks> public override bool TrySetDocument(PublishedContentRequest docRequest) { IPublishedContent node = null; string path = docRequest.Uri.GetAbsolutePathDecoded(); if (docRequest.HasDomain) { path = DomainHelper.PathRelativeToDomain(docRequest.DomainUri, path); } if (path != "/") // no template if "/" { var pos = path.LastIndexOf('/'); var templateAlias = path.Substring(pos + 1); path = pos == 0 ? "/" : path.Substring(0, pos); //TODO: We need to check if the altTemplate is for MVC or not, though I'm not exactly sure how the best // way to do that would be since the template is just an alias and if we are not having a flag on the // doc type for rendering engine and basing it only on template name, then how would we handle this? var template = Template.GetByAlias(templateAlias); if (template != null) { LogHelper.Debug <LookupByNiceUrlAndTemplate>("Valid template: \"{0}\"", () => templateAlias); var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path; node = LookupDocumentNode(docRequest, route); if (node != null) { docRequest.Template = template; } } else { LogHelper.Debug <LookupByNiceUrlAndTemplate>("Not a valid template: \"{0}\"", () => templateAlias); } } else { LogHelper.Debug <LookupByNiceUrlAndTemplate>("No template in path \"/\""); } return(node != null); }
public static Template Import(XmlNode n, User u) { string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("Alias")); Template t = Template.GetByAlias(alias); var design = xmlHelper.GetNodeValue(n.SelectSingleNode("Design")); if (t == null) { //create the template with the design if one is specified t = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("Name")), u, design.IsNullOrWhiteSpace() ? null : design); } t.Alias = alias; return(t); }