forked from umbraco/Umbraco-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request umbraco#11317 from matthewcare/custom-default-view…
…-content Ability to register your own content provider for default template content
- Loading branch information
Showing
13 changed files
with
170 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Text; | ||
using Umbraco.Extensions; | ||
|
||
namespace Umbraco.Cms.Core.IO | ||
{ | ||
public class DefaultViewContentProvider : IDefaultViewContentProvider | ||
{ | ||
public string GetDefaultFileContent(string layoutPageAlias = null, string modelClassName = null, string modelNamespace = null, string modelNamespaceAlias = null) | ||
{ | ||
var content = new StringBuilder(); | ||
|
||
if (string.IsNullOrWhiteSpace(modelNamespaceAlias)) | ||
modelNamespaceAlias = "ContentModels"; | ||
|
||
// either | ||
// @inherits Umbraco.Web.Mvc.UmbracoViewPage | ||
// @inherits Umbraco.Web.Mvc.UmbracoViewPage<ModelClass> | ||
content.AppendLine("@using Umbraco.Cms.Web.Common.PublishedModels;"); | ||
content.Append("@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage"); | ||
if (modelClassName.IsNullOrWhiteSpace() == false) | ||
{ | ||
content.Append("<"); | ||
if (modelNamespace.IsNullOrWhiteSpace() == false) | ||
{ | ||
content.Append(modelNamespaceAlias); | ||
content.Append("."); | ||
} | ||
content.Append(modelClassName); | ||
content.Append(">"); | ||
} | ||
content.Append("\r\n"); | ||
|
||
// if required, add | ||
// @using ContentModels = ModelNamespace; | ||
if (modelClassName.IsNullOrWhiteSpace() == false && modelNamespace.IsNullOrWhiteSpace() == false) | ||
{ | ||
content.Append("@using "); | ||
content.Append(modelNamespaceAlias); | ||
content.Append(" = "); | ||
content.Append(modelNamespace); | ||
content.Append(";\r\n"); | ||
} | ||
|
||
// either | ||
// Layout = null; | ||
// Layout = "layoutPage.cshtml"; | ||
content.Append("@{\r\n\tLayout = "); | ||
if (layoutPageAlias.IsNullOrWhiteSpace()) | ||
{ | ||
content.Append("null"); | ||
} | ||
else | ||
{ | ||
content.Append("\""); | ||
content.Append(layoutPageAlias); | ||
content.Append(".cshtml\""); | ||
} | ||
content.Append(";\r\n}"); | ||
return content.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Umbraco.Cms.Core.IO | ||
{ | ||
public interface IDefaultViewContentProvider | ||
{ | ||
string GetDefaultFileContent(string layoutPageAlias = null, string modelClassName = null, | ||
string modelNamespace = null, string modelNamespaceAlias = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Umbraco.Cms.Core.Models; | ||
|
||
namespace Umbraco.Cms.Core.IO | ||
{ | ||
public interface IViewHelper | ||
{ | ||
bool ViewExists(ITemplate t); | ||
string GetFileContents(ITemplate t); | ||
string CreateView(ITemplate t, bool overWrite = false); | ||
string UpdateViewFile(ITemplate t, string currentAlias = null); | ||
string ViewPath(string alias); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.