Copied to clipboard

Flag this post as spam?

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


  • Berend Haan 2 posts 32 karma points
    Sep 09, 2014 @ 14:10
    Berend Haan
    0

    Setting a template IContentFinder

    Hi there,

    I'm working on a Umbraco 6 website which has a page that displays some YouTube videos. These videos can be nodes under the VideoPage node and can be on nodes of a different type (Highlight).

    The url structure is as follows: /videos/name-of-the-video.

    This structure works for nodes under the VideoPage but not for the videos that are on a Highlight.

    So I created an class which implements the IContent interface and changed the PublishedContent of the contentRequest object. This will render the Highlight as is, and not the template of the VideoPage.

    Can you change the template programmatically? I tried contentRequest.SetTemplate, but the page went blank with the following parameters:

    Template template = new Template("/Masterpages/VideoPage.master""Video Page""VideoPage");
    
                            contentRequest.PublishedContent = content; // The content
                            contentRequest.SetTemplate(template);

    Am I’m doing something wrong or is this not possible in the current Umbraco?

    Berend

  • Stephen 767 posts 2273 karma points c-trib
    Sep 09, 2014 @ 14:21
    Stephen
    102

    Not sure I understand. What you describe seems possible but... when you do new Template(...) you do not retrieve an existing template, you just create an empty template that does not correspond to anything, hence the blank page. I guess what you really want is get the template that should already exist:

    var template = ApplicationContext.Current.Services.FileService.GetTemplate("VideoPage");

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 09, 2014 @ 14:33
    Jeroen Breuer
    1

    Hello,

    Could you try this:

    var template = ApplicationContext.Current.Services.FileService.GetTemplate(content.TemplateId);
    contentRequest.PublishedContent = content;
    contentRequest.TrySetTemplate(template.Alias);

    Jeroen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 09, 2014 @ 14:39
    Jeroen Breuer
    3

    If you already know the alias of the template this is the easiest:

    contentRequest.TrySetTemplate("VideoPage");

    Jeroen

  • Berend Haan 2 posts 32 karma points
    Sep 09, 2014 @ 14:40
    Berend Haan
    0

    Thanks Stephan, it worked! I thought it worked like the old api, new Node(NodeId).

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 09, 2014 @ 14:45
    Jeroen Breuer
    0

    If you don't set the template programmatically and you go to the url that the content finder handles you can also set the template by adding ?alttemplate=alias in the querystring. Even content finders support alt templates :-).

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft