Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Prothero 4 posts 24 karma points
    Jun 08, 2015 @ 19:14
    David Prothero
    0

    Global default template?

    If you try to preview content that does not have a template specified, you get the 404 page. I would like to be able to default to a specific template (as opposed to creating a custom 404 page). Is this possible? Some way to hook into the process that looks for a template?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 09, 2015 @ 17:06
    Jeavon Leopold
    0

    Hi David,

    To do this you you will need to create a IContentFInder to find the content you would like to return. Creating a IContentFinder is documented here.

    Can I ask why you would want to do this?

    Jeavon

  • David Prothero 4 posts 24 karma points
    Jun 09, 2015 @ 18:08
    David Prothero
    0

    Thanks Jeavon, that's the type of thing I was looking for. I was able to implement what I needed using an "error404" page.

    I'm using Umbraco for the back-office only. The web site is hosted on a stand-alone ASP.NET website. When content is published in Umbraco, I push it into Azure blob storage where the ASP.NET web site can use it. This achieves a decoupling of the CMS from the website itself. Theoretically, I could use any CMS and leave the public site completely unchanged. (In fact, I did a proof of concept with SharePoint, but the customer preferred Umbraco, thank goodness.)

    Anyway, what I was trying to achieve was to hack the Preview functionality in the Umbraco back-office. I didn't want to have to create templates for all of the different document types. I built one simple "previewer" template and made that the default template. It then redirects the user to preview the content on the actual website (I am keeping drafts separate from published content in blob storage).

    contentPreviewer.cshtml:

    @inherits UmbracoTemplatePage
    @{
      var id = int.Parse(Path.GetFileNameWithoutExtension(Request.Url.AbsolutePath));
      var item = Umbraco.Content(id);
      var itemTag = StringHelpers.RemoveSpecialCharacters(item.Name);
    
      var previewUrl = ConfigurationManager.AppSettings["cea:ContentApiBaseUrl"];
    
      switch (item.DocumentTypeAlias as string)
      {
        case "contentPage":
          previewUrl += "Content/" + itemTag;
          break;
      }
    
      previewUrl += (previewUrl.Contains("?") ? "&" : "?") + "draft=1";
    }
    
    <script type="text/javascript">// <![CDATA[
      top.location.href = "@previewUrl";
    // ]]></script>

    It's working great!

Please Sign in or register to post replies

Write your reply to:

Draft