diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
index 577a6cc603..63ebcd4e16 100644
--- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
+++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
@@ -2167,7 +2167,6 @@
Code
-
@@ -2192,21 +2191,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -2664,6 +2648,7 @@
+
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Breadcrumb.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Breadcrumb.cshtml
deleted file mode 100644
index 3f3dcfd3b6..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Breadcrumb.cshtml
+++ /dev/null
@@ -1,22 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-@*
- This snippet makes a breadcrumb of parents using an unordred html list.
-
- How it works:
- - It uses the Ancestors() method to get all parents and then generates links so the visitor get go back
- - Finally it outputs the name of the current page (without a link)
-*@
-
-@if (CurrentPage.Ancestors().Any())
-{
-
- @* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
- @foreach (var page in CurrentPage.Ancestors().OrderBy("Level"))
- {
-
- }
-
- @* Display the current page as the last item in the list *@
-
@CurrentPage.Name
-
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/EditProfile.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/EditProfile.cshtml
deleted file mode 100644
index 43b7521b8d..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/EditProfile.cshtml
+++ /dev/null
@@ -1,54 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@using System.Web.Mvc.Html
-@using ClientDependency.Core.Mvc
-@using Umbraco.Web
-@using Umbraco.Web.Models
-@using Umbraco.Web.Controllers
-
-@{
- var profileModel = Members.CreateProfileModel();
-
- Html.EnableClientValidation();
- Html.EnableUnobtrusiveJavaScript();
- Html.RequiresJs("/umbraco_client/ui/jquery.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
-}
-
-@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
-@Html.RenderJsHere()
-
-@if (Members.IsLoggedIn())
-{
- using (Html.BeginUmbracoForm("HandleUpdateProfile"))
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty (ForUseWithCustomViews).cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty (ForUseWithCustomViews).cshtml
deleted file mode 100644
index 8d10a3a9c7..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty (ForUseWithCustomViews).cshtml
+++ /dev/null
@@ -1 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoViewPage
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty.cshtml
deleted file mode 100644
index 2363dcc14c..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Empty.cshtml
+++ /dev/null
@@ -1 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListAncestorsFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListAncestorsFromCurrentPage.cshtml
deleted file mode 100644
index 7ce864c204..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListAncestorsFromCurrentPage.cshtml
+++ /dev/null
@@ -1,16 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@* Check the current page has ancestors *@
-@if (CurrentPage.Ancestors().Any())
-{
-
- @* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
- @foreach (var page in CurrentPage.Ancestors().OrderBy("Level"))
- {
-
- }
-
- @* Display the current page as the last item in the list *@
-
@CurrentPage.Name
-
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesFromCurrentPage.cshtml
deleted file mode 100644
index d53af0560b..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesFromCurrentPage.cshtml
+++ /dev/null
@@ -1,15 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
-@if (CurrentPage.Children.Where("Visible").Any())
-{
-
- @* For each child page under the root node, where the property umbracoNaviHide is not True *@
- @foreach (var childPage in CurrentPage.Children.Where("Visible"))
- {
-
- @*OrderBy() takes the property to sort by and optionally order desc/asc *@
-
- @foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc"))
- {
-
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesWithDoctype.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesWithDoctype.cshtml
deleted file mode 100644
index 322058b881..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListChildPagesWithDoctype.cshtml
+++ /dev/null
@@ -1,32 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@*
- This snippet shows how simple it is to fetch only children of a certain Document Type using Razor. Instead of
- calling .Children, simply call .AliasOfDocumentType in plural.
- For instance .Textpages or .NewsArticles (you can find the alias of your Document Type by editing it in the
- Settings section).
-*@
-
-
-@{
- @*Build a query and return the visible items *@
- var selection= CurrentPage.Textpages.Where("Visible");
-
- @*
- Example of more querying, if you have a true/false property with the alias of shouldBeFeatured:
- var selection= Model.Textpages.Where("shouldBeFeatured == true").Where("Visible");
- *@
-}
-
-
-@*Determine if there are any nodes in the selection, then render list *@
-@if(selection.Any()){
-
-
-
-}
-
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListDescendantsFromCurrentPage.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListDescendantsFromCurrentPage.cshtml
deleted file mode 100644
index 76642a68f6..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/ListDescendantsFromCurrentPage.cshtml
+++ /dev/null
@@ -1,54 +0,0 @@
-@inherits Umbraco.Web.Macros.PartialViewMacroPage
-
-@* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
-@if (CurrentPage.Children.Where("Visible").Any())
-{
- @* Get the first page in the children, where the property umbracoNaviHide is not True *@
- var naviLevel = CurrentPage.Children.Where("Visible").First().Level;
-
- @* Add in level for a CSS hook *@
-
- @* For each child page under the root node, where the property umbracoNaviHide is not True *@
- @foreach (var childPage in CurrentPage.Children.Where("Visible"))
- {
-
- @childPage.Name
-
- @* if the current page has any children, where the property umbracoNaviHide is not True *@
- @if (childPage.Children.Where("Visible").Any())
- {
- @* Call our helper to display the children *@
- @childPages(childPage.Children)
- }
-
- }
-
-}
-
-
-@helper childPages(dynamic pages)
- {
- @* Ensure that we have a collection of pages *@
- if (pages.Any())
- {
- @* Get the first page in pages and get the level *@
- var naviLevel = pages.First().Level;
-
- @* Add in level for a CSS hook *@
-
- @foreach (var page in pages.Where("Visible"))
- {
-
- @page.Name
-
- @* if the current page has any children, where the property umbracoNaviHide is not True *@
- @if (page.Children.Where("Visible").Any())
- {
- @* Call our helper to display the children *@
- @childPages(page.Children)
- }
-
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Login.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Login.cshtml
deleted file mode 100644
index 89fa40c8ba..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Login.cshtml
+++ /dev/null
@@ -1,41 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@using System.Web.Mvc.Html
-@using ClientDependency.Core.Mvc
-@using Umbraco.Web
-@using Umbraco.Web.Models
-@using Umbraco.Web.Controllers
-
-@{
- var loginModel = new LoginModel();
-
- Html.EnableClientValidation();
- Html.EnableUnobtrusiveJavaScript();
- Html.RequiresJs("/umbraco_client/ui/jquery.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
-}
-
-@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
-@Html.RenderJsHere()
-
-@using (Html.BeginUmbracoForm("HandleLogin"))
-{
-
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/LoginStatus.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/LoginStatus.cshtml
deleted file mode 100644
index f48a4e5d2a..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/LoginStatus.cshtml
+++ /dev/null
@@ -1,32 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@using ClientDependency.Core.Mvc
-@using Umbraco.Web
-@using Umbraco.Web.Models
-@using Umbraco.Web.Controllers
-
-@{
- var loginStatusModel = Members.GetCurrentLoginStatus();
-
- Html.EnableClientValidation();
- Html.EnableUnobtrusiveJavaScript();
- Html.RequiresJs("/umbraco_client/ui/jquery.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
-}
-
-@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
-@Html.RenderJsHere()
-
-@if (loginStatusModel.IsLoggedIn)
-{
-
You are currently logged in as @loginStatusModel.Name
-
- using (Html.BeginUmbracoForm("HandleLogout"))
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/MultinodeTree-picker.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/MultinodeTree-picker.cshtml
deleted file mode 100644
index 2cefb8d8ba..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/MultinodeTree-picker.cshtml
+++ /dev/null
@@ -1,20 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@*
- Macro to list nodes from a Multinode tree picker, using the pickers default settings.
- Content Values stored as xml.
-
- To get it working with any site's data structure, simply set the selection equal to the property which has the
- multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
-*@
-
-@* Lists each selected value from the picker as a link *@
-
- @foreach(var id in CurrentPage.PropertyWithPicker){
-
- @*For each link, get the node, and display its name and url*@
- var content = Umbraco.Content(id.InnerText);
-
-
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Navigation.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Navigation.cshtml
deleted file mode 100644
index cd9efe8b35..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/Navigation.cshtml
+++ /dev/null
@@ -1,22 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@*
- Macro to display child pages below the root page of a standard website.
- Also highlights the current active page/section in the navigation with
- the css class "current".
-*@
-
-
-@{
- @*Get the root of the website *@
- var root = CurrentPage.AncestorOrSelf(1);
-}
-
-
- @foreach (var page in root.Children.Where("Visible"))
- {
-
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/RegisterMember.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/RegisterMember.cshtml
deleted file mode 100644
index 98b1dcb20f..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/RegisterMember.cshtml
+++ /dev/null
@@ -1,91 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@using System.Web.Mvc.Html
-@using ClientDependency.Core.Mvc
-@using Umbraco.Web
-@using Umbraco.Web.Models
-@using Umbraco.Web.Controllers
-
-@{
- var registerModel = Members.CreateRegistrationModel();
-
- @*
- Configurable here:
-
- registerModel.MemberTypeAlias - the default is "Member"
-
- registerModel.RedirectOnSucces - the default is false
-
- registerModel.RedirectUrl - what page do we go to if the registration was successful?
- the default is "/" unless RedirectOnSuccess is set to false
-
- registerModel.UsernameIsEmail - the default is true
- if you want the username to be different from the email
- address, set this to true and add a new Username field in
- the form below
-
- @Html.LabelFor(m => registerModel.Username)
- @Html.TextBoxFor(m => registerModel.Username)
- @Html.ValidationMessageFor(m => registerModel.Username)
- *@
-
- Html.EnableClientValidation();
- Html.EnableUnobtrusiveJavaScript();
- Html.RequiresJs("/umbraco_client/ui/jquery.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
- Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
-
- var success = TempData["FormSuccess"] != null;
-}
-
-@*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@
-@Html.RenderJsHere()
-
-@if (success)
-{
- // This message will show if RedirectOnSucces is set to false (default)
-
Registration succeeeded.
-}
-else
-{
- using (Html.BeginUmbracoForm("HandleRegisterMember"))
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/SiteMap.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/SiteMap.cshtml
deleted file mode 100644
index 6e08a509cd..0000000000
--- a/src/Umbraco.Web.UI/Umbraco/PartialViews/Templates/SiteMap.cshtml
+++ /dev/null
@@ -1,32 +0,0 @@
-@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
-
-@*Render the sitemap by passing the root node to the traverse helper*@
-
- @Traverse(CurrentPage.AncestorOrSelf())
-
-
-@*Helper method to travers through all descendants*@
-@helper Traverse(dynamic node)
-{
- @* Update the level to reflect how deep you want the sitemap to go *@
- var maxLevelForSitemap = 4;
-
- @*Select visible children *@
- var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
-
- @*If any items are returned, render a list *@
- if (items.Any())
- {
-
- @foreach (var item in items)
- {
-
- @item.Name
-
- @*Run the traverse helper again *@
- @Traverse(item)
-
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Web.UI/Umbraco/create/PartialView.ascx.cs b/src/Umbraco.Web.UI/Umbraco/create/PartialView.ascx.cs
index 777adfec01..2aa2d519b1 100644
--- a/src/Umbraco.Web.UI/Umbraco/create/PartialView.ascx.cs
+++ b/src/Umbraco.Web.UI/Umbraco/create/PartialView.ascx.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
@@ -21,26 +23,66 @@ namespace Umbraco.Web.UI.Umbraco.Create
private static void LoadTemplates(ListControl list)
{
- var path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/");
+ var partialViewTemplatePath = new
+ {
+ path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/"),
+ include = new string[]{}
+ };
+ //include these templates from the partial view macro templates!
+ var partialViewMacrosTemplatePath = new
+ {
+ path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViewMacros/Templates/"),
+ include = new[]
+ {
+ "Breadcrumb",
+ "EditProfile",
+ "Empty (ForUseWithCustomViews)",
+ "Empty",
+ "ListAncestorsFromCurrentPage",
+ "ListChildPagesFromCurrentPage",
+ "ListChildPagesOrderedByDate",
+ "ListChildPagesOrderedByName",
+ "ListChildPagesWithDoctype",
+ "ListDescendantsFromCurrentPage",
+ "Login",
+ "LoginStatus",
+ "MultinodeTree-picker",
+ "Navigation",
+ "RegisterMember",
+ "SiteMap"
+ }
+ };
+ var paths = new[] { partialViewTemplatePath, partialViewMacrosTemplatePath };
+ const string extension = ".cshtml";
+ var namesAdded = new List();
+
list.Items.Clear();
// always add the options of empty snippets
list.Items.Add(new ListItem("Empty", "Empty.cshtml"));
list.Items.Add(new ListItem("Empty (For Use With Custom Views)", "Empty (ForUseWithCustomViews).cshtml"));
-
- if (System.IO.Directory.Exists(path))
+
+ foreach (var pathFilter in paths)
{
- const string extension = ".cshtml";
-
- //Already adding Empty as the first item, so don't add it again
- foreach (var fileInfo in new System.IO.DirectoryInfo(path).GetFiles("*" + extension).Where(f => f.Name.StartsWith("Empty") == false))
+ if (Directory.Exists(pathFilter.path) == false) continue;
+
+ var p = pathFilter;
+ foreach (var fileInfo in new DirectoryInfo(pathFilter.path).GetFiles("*" + extension)
+ //check if we've already added this name
+ .Where(f => namesAdded.InvariantContains(f.Name) == false)
+ //Already adding Empty as the first item, so don't add it again
+ .Where(f => f.Name.StartsWith("Empty") == false)
+ //don't add if not in the inclusion list
+ .Where(f => p.include.Length == 0 || (p.include.Length > 0 && p.include.InvariantContains(f.Name) == false)))
{
- var filename = System.IO.Path.GetFileName(fileInfo.FullName);
-
+ var filename = Path.GetFileName(fileInfo.FullName);
+ namesAdded.Add(filename);
var liText = filename.Replace(extension, "").SplitPascalCasing().ToFirstUpperInvariant();
list.Items.Add(new ListItem(liText, filename));
}
}
+
+
}
protected void SubmitButton_Click(object sender, System.EventArgs e)
diff --git a/src/Umbraco.Web.UI/umbraco/create/PartialViewMacro.ascx.cs b/src/Umbraco.Web.UI/umbraco/create/PartialViewMacro.ascx.cs
index 4e06c08cd4..bfd2343fc8 100644
--- a/src/Umbraco.Web.UI/umbraco/create/PartialViewMacro.ascx.cs
+++ b/src/Umbraco.Web.UI/umbraco/create/PartialViewMacro.ascx.cs
@@ -11,6 +11,8 @@ namespace Umbraco.Web.UI.Umbraco.Create
{
public partial class PartialViewMacro : UserControl
{
+
+
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewMacrosTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewMacrosTasks.cs
index f939ba51a9..de54b07961 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewMacrosTasks.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewMacrosTasks.cs
@@ -1,4 +1,6 @@
-using System.IO;
+using System;
+using System.IO;
+using System.Text.RegularExpressions;
using System.Web;
using Umbraco.Core.CodeAnnotations;
using Umbraco.Core.IO;
@@ -15,6 +17,9 @@ namespace umbraco
[UmbracoWillObsolete("http://issues.umbraco.org/issue/U4-1373", "This will one day be removed when we overhaul the create process")]
public class PartialViewMacroTasks : interfaces.ITaskReturnUrl
{
+ private const string CodeHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage";
+ private readonly Regex _headerMatch = new Regex("^@inherits\\s+?.*$", RegexOptions.Multiline | RegexOptions.Compiled);
+
private string _alias;
private int _parentId;
private int _typeId;
@@ -60,7 +65,7 @@ namespace umbraco
public bool Save()
{
- var pipesIndex = _alias.IndexOf("|||", System.StringComparison.Ordinal);
+ var pipesIndex = _alias.IndexOf("|||", StringComparison.Ordinal);
var template = _alias.Substring(0, pipesIndex).Trim();
var fileName = _alias.Substring(pipesIndex + 3, _alias.Length - pipesIndex - 3) + ".cshtml";
@@ -78,8 +83,16 @@ namespace umbraco
{
using (var templateFile = File.OpenText(IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViewMacros/Templates/" + template)))
{
- var templateContent = templateFile.ReadToEnd();
- sw.Write(templateContent);
+ var templateContent = templateFile.ReadToEnd().Trim();
+
+ //strip the @inherits if it's there
+ templateContent = _headerMatch.Replace(templateContent, string.Empty);
+
+ sw.Write(
+ "{0}{1}{2}",
+ CodeHeader,
+ Environment.NewLine,
+ templateContent);
}
}
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs
index 78550060a2..1bf0c7496b 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs
@@ -1,4 +1,6 @@
-using System.IO;
+using System;
+using System.IO;
+using System.Text.RegularExpressions;
using System.Web;
using Umbraco.Core.CodeAnnotations;
using Umbraco.Core.IO;
@@ -15,6 +17,9 @@ namespace umbraco
[UmbracoWillObsolete("http://issues.umbraco.org/issue/U4-1373", "This will one day be removed when we overhaul the create process")]
public class PartialViewTasks : interfaces.ITaskReturnUrl
{
+ private const string CodeHeader = "@inherits Umbraco.Web.Mvc.UmbracoTemplatePage";
+ private readonly Regex _headerMatch = new Regex("^@inherits\\s+?.*$", RegexOptions.Multiline | RegexOptions.Compiled);
+
private string _alias;
private int _parentId;
private int _typeId;
@@ -60,7 +65,7 @@ namespace umbraco
public bool Save()
{
- var pipesIndex = _alias.IndexOf("|||", System.StringComparison.Ordinal);
+ var pipesIndex = _alias.IndexOf("|||", StringComparison.Ordinal);
var template = _alias.Substring(0, pipesIndex).Trim();
var fileName = _alias.Substring(pipesIndex + 3, _alias.Length - pipesIndex - 3) + ".cshtml";
@@ -76,10 +81,24 @@ namespace umbraco
//create the file
using (var sw = File.CreateText(fullFilePath))
{
- using (var templateFile = File.OpenText(IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/" + template)))
+ var templatePathAttempt = TryGetTemplatePath(template);
+ if (templatePathAttempt.Success == false)
{
- var templateContent = templateFile.ReadToEnd();
- sw.Write(templateContent);
+ throw new InvalidOperationException("Could not load template with name " + template);
+ }
+
+ using (var templateFile = File.OpenText(templatePathAttempt.Result))
+ {
+ var templateContent = templateFile.ReadToEnd().Trim();
+
+ //strip the @inherits if it's there
+ templateContent = _headerMatch.Replace(templateContent, string.Empty);
+
+ sw.Write(
+ "{0}{1}{2}",
+ CodeHeader,
+ Environment.NewLine,
+ templateContent);
}
}
@@ -119,5 +138,26 @@ namespace umbraco
}
#endregion
+
+ ///
+ /// Looks first in the Partial View template folder and then in the macro partials template folder if not found
+ ///
+ ///
+ ///
+ private Attempt TryGetTemplatePath(string fileName)
+ {
+ var templatePath = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViews/Templates/" + fileName);
+
+ if (File.Exists(templatePath))
+ {
+ return Attempt.Succeed(templatePath);
+ }
+
+ templatePath = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViewMacros/Templates/" + fileName);
+
+ return File.Exists(templatePath)
+ ? Attempt.Succeed(templatePath)
+ : Attempt.Fail();
+ }
}
}
\ No newline at end of file