Copied to clipboard

Flag this post as spam?

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


  • Jan 4 posts 75 karma points
    Aug 28, 2015 @ 10:27
    Jan
    1

    RenderTemplate with specific folders / ViewLocationFormats

    Hi there,

    my name is Jan I'm new in using Umbraco. :)

    I try to use subfolders for my templates (views) and this is why I'm registering these folders in "ViewLocationFormats" at the application start.

    It works fine for automatically rendered templates (just calling the URL) but does not when I'm calling Umbraco.RenderTemplate (nodeID) inside a template by razor code.

    Has anyone an idea that could help me? Maybe I'm doing something wrong or there is an alternative to "RenderTemplate".

    Thanks in advance!

    Jan

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Aug 28, 2015 @ 22:10
    Marc Goodson
    0

    Hi Jan

    Are you using MVC Views ?

    Html.Partial("PartialViewName")

    or

    Html.Partial("~/pathto/partialview.cshtml")

    should render a partial view in a template.

    If you want to render a 'different template view' for the content other than the one it is published under, you can use ?altTemplate=othertemplatealias in the querystring

    eg

    /hompage/news?altTemplate=altNewsListing

    would load the news page node with the altNewsListing template

    furthermore so would:

    /homepage/news/altNewsListing

    this is default behaviour for versions of Umbraco, but can be turned off in umbracoSettings.config for versions 7.2.*

    by disabling alternative templates

    eg:

      <web.routing
        trySkipIisCustomErrors="false"
        internalRedirectPreservesTemplate="false" disableAlternativeTemplates="false" disableFindContentByIdPath="false"
        umbracoApplicationUrl="">
      </web.routing>
    
  • Jan 4 posts 75 karma points
    Sep 03, 2015 @ 16:17
    Jan
    0

    Hi Marc,

    thank you very much for your answer.

    The view is generated by Umbraco and I just moved it to my subfolder. In the view I iterate through the child nodes.

    foreach (var child in page.Children) { @Umbraco.RenderTemplate(child.Id); @child.Id }

    Could this work with a partial view? I think there wouldn't be a connection to the Umbraco content and its fields or am I wrong?

    To render a different template maybe will be interesting later but in this case I want to render the "content template".

    Thanks

    Jan

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 03, 2015 @ 19:30
    Marc Goodson
    0

    Hi Jan

    The way I normally kind of do child component templating thing is with partial views: eg

    foreach(var child in page.Children) {
    
    var partialViewName = "ListItem" + child.DocumentTypeAlias;
    
    @Html.Partial(partialViewName, child)
    
    }
    

    Then I have a matching partial view name called

    ListItemDocTypeAlias

    which inherits:

    @inherits UmbracoViewPage<IPublishedContent>
    

    and where DocTypeAlias is the alias of the doctype you are looping through.

    Because you pass the child content as the 'model' inside the Partial View you can read all the properties of the child node, and write out the relevant html for your loop...

    if that makes sense ?

  • Jan 4 posts 75 karma points
    Sep 23, 2015 @ 09:49
    Jan
    0

    Sorry for this late answer, Marc!

    In the last weeks I did not work on Umbraco - so let me first thank you for your fast answer!

    I'm not sure what's the benefit in using partial views instead of "regular" templates because you have to use this specific naming convention and on the other hand it could work with templates "naturally".

    What's your reason for doing it this way? Maybe it's better to keep the number of templates a small as possible?

    Thanks for your friendly help! :)

    Jan

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Sep 24, 2015 @ 23:52
    Marc Goodson
    0

    Hi Jan

    I think I slightly misunderstand your question originally, I would use the approach described above, if the children, or items to loop through were 'picked' and the items all had different doctypes / and required different html templates for displaying each item in the loop.

    If you just want to loop through the child nodes of a page, then yes it just makes sense to do that in main page template view and have:

    foreach(var child in page.Children) {
    <li><a href="@child.Url">@child.Name</a></li>
    }
    

    etc

    to write out your child content items in your desired html for each item.

    I'd put this into a partial (or macro partial) if I wanted to reuse this looping / html on another view-template.

    I have only used Umbraco.RenderTemplate with XSLT in the past, so I'm not sure, but I think it also takes an optional second parameter of the templateId, you would like to render the node eg:

    Umbraco.RenderTemplate(nodeId,templateId)
    

    Maybe that would help it find the appropriate template from your views subfolders. Be interested to know if that 'works'

  • Jan 4 posts 75 karma points
    Sep 25, 2015 @ 09:55
    Jan
    0

    Hi Marc,

    thanks again for your support.

    In general it works to use the templateID but in my special case - views in a sub folder - it still does not.

    I think I have to take some more time or ask an "Umbraco agency".

    Thank you so far for your fast und very friendly help! :)

    Jan

Please Sign in or register to post replies

Write your reply to:

Draft