diff --git a/src/Umbraco.Web/Editors/CodeFileController.cs b/src/Umbraco.Web/Editors/CodeFileController.cs
index 60dcf624a0..4f1be8563a 100644
--- a/src/Umbraco.Web/Editors/CodeFileController.cs
+++ b/src/Umbraco.Web/Editors/CodeFileController.cs
@@ -1,7 +1,10 @@
using AutoMapper;
+using System.Collections.Generic;
+using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
+using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
@@ -100,6 +103,39 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
+ ///
+ /// Used to get a list of available templates/snippets to base a new Partial View og Partial View Macro from
+ ///
+ /// This is a string but will be 'partialViews', 'partialViewMacros'
+ /// Returns a list of if a correct type is sent
+ public IEnumerable GetSnippets(string type)
+ {
+ if (string.IsNullOrWhiteSpace(type))
+ {
+ throw new HttpResponseException(HttpStatusCode.BadRequest);
+ }
+
+ IEnumerable snippets;
+ switch (type)
+ {
+ case Core.Constants.Trees.PartialViews:
+ snippets = Services.FileService.GetPartialViewSnippetNames(
+ //ignore these - (this is taken from the logic in "PartialView.ascx.cs")
+ "Gallery",
+ "ListChildPagesFromChangeableSource",
+ "ListChildPagesOrderedByProperty",
+ "ListImagesFromMediaFolder");
+ break;
+ case Core.Constants.Trees.PartialViewMacros:
+ snippets = Services.FileService.GetPartialViewSnippetNames();
+ break;
+ default:
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+
+ return snippets.Select(snippet => new SnippetDisplay() {Name = snippet.SplitPascalCasing().ToFirstUpperInvariant(), FileName = snippet});
+ }
+
///
/// Used to delete a specific file from disk via the FileService
///
diff --git a/src/Umbraco.Web/Models/ContentEditing/SnippetDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/SnippetDisplay.cs
new file mode 100644
index 0000000000..e05f8c5c89
--- /dev/null
+++ b/src/Umbraco.Web/Models/ContentEditing/SnippetDisplay.cs
@@ -0,0 +1,14 @@
+using System.Runtime.Serialization;
+
+namespace Umbraco.Web.Models.ContentEditing
+{
+ [DataContract(Name = "scriptFile", Namespace = "")]
+ public class SnippetDisplay
+ {
+ [DataMember(Name = "name", IsRequired = true)]
+ public string Name { get; set; }
+
+ [DataMember(Name = "fileName", IsRequired = true)]
+ public string FileName { get; set; }
+ }
+}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 68bb81fad7..f65ac1fce2 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -339,6 +339,7 @@
+