Copied to clipboard

Flag this post as spam?

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


  • steven smith 20 posts 130 karma points
    Aug 05, 2014 @ 16:06
    steven smith
    0

    Descendants of template

    hey guys ive recently used the smartblog plugin for my news section in 7.1 umbraco

    So far so good, theres another section where the design is very similar to this so i wanted to re-use.

    i left the content types the same and decided to create a new set of templates that are very close to the original, then create content pages from those new templates, which seems fine.

    However when i try to check my functionality i noticed that i use this line on my templates.

        IPublishedContent blogRoot = Model.Content.AncestorOrSelf("SmartBlogBlog");

    Checking this, it find tbhe alias of a content type.......Oh dear :(

    What i need is the exact same functionality, only finding the descendants based on template alias rather then contentType alias.

    Any ideas? is that possible?  If not will i be forced to make new content types?

    cheers guys

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Aug 05, 2014 @ 17:36
    Andy Butland
    0

    Does this work?

    var blogRoot = Model.Content.AncestorsOrSelf()
        .FirstOrDefault(x => x.GetTemplateAlias() == "SmartBlogBlog");

    Andy

  • steven smith 20 posts 130 karma points
    Aug 05, 2014 @ 18:19
    steven smith
    0

    got switched onto a lovely email build, will check tomorrow, but that seems like it will work at first glance.  Cheers for that Andy!

  • steven smith 20 posts 130 karma points
    Aug 06, 2014 @ 11:25
    steven smith
    100

    hey andy tried it, but It says IpublishedContent does not have an extension method for FirstOrDefault().  Any alternative?

  • steven smith 20 posts 130 karma points
    Aug 06, 2014 @ 11:50
    steven smith
    0

    investiagting turns out thats what ancesterordelf actually does, it gets the correct template information so theres actually no code change haha. 

    thanks anyway 

Please Sign in or register to post replies

Write your reply to:

Draft