Copied to clipboard

Flag this post as spam?

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


  • bh 211 posts 720 karma points
    Mar 08, 2019 @ 13:49
    bh
    1

    How to get CurrentPage in v8

    I've been using @inherits Umbraco.Web.Mvc.UmbracoTemplatePage to build my canonical like so <link rel="canonical" href="httpsP@HttpContext.Current.Request.Url.Host@CurrentPage.Url" runat="server" id="canonical" />, but either v8 doesn't have UmbracoTemplatePage anymore or it's moved. If it's moved can someone point me to where it is now. If it's gone, could you suggest how I get the current page's url?

    I'm a day into my first v8 project. Gotta say I'm perplexed at the lack of documentation available. It's cool if you're going to change stuff. Just have a page somewhere that says, this used to work, now it's like this. That's all I need. I've been struggling to find v8 documentation. If you've got a bead on where I can find some good documentation on moving from v7 to v8 I'd really appreciate a link.

  • Sebastiaan Janssen 4850 posts 14395 karma points MVP admin hq
    Mar 08, 2019 @ 14:48
    Sebastiaan Janssen
    100

    Hey there Ben, make sure to have a look at the documentation statuspage: https://our.umbraco.com/documentation/v8documentation

    If you look at the template we give you when you create it, you'll see:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Testers>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = null;
    }
    

    Note: My document type is called Testers, hence the Testers model name in there.

    UmbracoViewPage is nothing new, we've had that in Umbraco for years. I think it was also possible to have a typed version like here (UmbracoViewPage<ContentModels.Testers>).

    You're able to remove the type as well if you want: @inherits Umbraco.Web.Mvc.UmbracoViewPage.

    In both cases, you can then use @Model.Url to get the URL of the "CurrentPage" (Model). Not much else has changed, let's hope you find your way a little bit better from this starting point.

    Shannon also spoke about the v8 changes recently and his slides are here, they could come in helpful: https://shazwazza.com/media/1032/uduf-2019.pdf

  • bh 211 posts 720 karma points
    Mar 08, 2019 @ 14:56
    bh
    0

    Many thanks @SebastiaanJanssen!

  • Anders Brohus 167 posts 407 karma points
    Mar 09, 2019 @ 20:12
    Anders Brohus
    0

    Hi Sebastiaan :)

    Maybe i missed something, but how can i get my root node (Frontpage) out as a model? :)

    In v7 i could do

    var rootNode = Model.Content.Site().OfType<Frontpage>();

    But that is not an option anymore :)

  • Frans de Jong 499 posts 1708 karma points c-trib
    Mar 09, 2019 @ 20:23
    Frans de Jong
    0

    Hi Anders,

    Instead of Model.Content.Site() try Model.Root()

  • Anders Brohus 167 posts 407 karma points
    Mar 09, 2019 @ 20:25
    Anders Brohus
    0

    Hi Frans :)

    Yeah i have done it with Model.Root() but the problem with Model.Root is that i does not give me the possibility to do this,

    var widgetImageGallery = rootNode.widgetImageGallery;
    

    I have to do this,

    var widgetImageGallery = rootNode.Value<IEnumerable<IPublishedContent>>("widgetImageGallery");
    

    The .OfType<FrontPage> is gone many places, and i can't find a replacement for it :(

  • Frans de Jong 499 posts 1708 karma points c-trib
    Mar 09, 2019 @ 20:31
    Frans de Jong
    2

    What I always do is:

    Frontpage frontpage = new Frontpage(Model.Root());
    

    You could also use Model.Root() as Fronpage but I have to update Rosalyn to be able to use Modelsbuilder for that one

  • Anders Brohus 167 posts 407 karma points
    Mar 09, 2019 @ 20:33
    Anders Brohus
    2

    Nice thanks!

    It works with

        var rootNode = Model.Root() as Frontpage;
    

    Thanks alot! :)

  • Damien Holley 68 posts 235 karma points
    Nov 03, 2019 @ 23:20
    Damien Holley
    0

    This is the best one as you can then test for nulls.

  • Tom 711 posts 948 karma points
    Aug 12, 2019 @ 02:43
    Tom
    0

    Just wondering with the document type model name that never resolves so we don't get any autocomplete on Model. is there a way to wire that up? Cheers, Tom

  • Frans de Jong 499 posts 1708 karma points c-trib
    Aug 12, 2019 @ 04:31
    Frans de Jong
    0

    Do you use modelsbuilder? And if so in what mode?

  • Tom 711 posts 948 karma points
    Aug 12, 2019 @ 06:29
    Tom
    0

    Thanks Frans, Currently PureLive

  • Frans de Jong 499 posts 1708 karma points c-trib
    Aug 12, 2019 @ 06:32
    Frans de Jong
    0

    Autocomplete doesn't work in purelive mode since models only exist runtime.

    I would strongly advice looking in to app data mode or, if you always use visual studio, use the modelsbuilder api.

  • john blair 33 posts 195 karma points
    Aug 19, 2019 @ 15:57
    john blair
    0

    Yes, its a total nightmare finding alternatives that used to work in v7. Surprised the Umbraco team never gave this much thought.

  • Paul Seal 391 posts 2123 karma points MVP 2x c-trib
    Aug 20, 2019 @ 22:25
    Paul Seal
    1

    I like to do this:

    var homePage = Model.AncestorOrSelf<Home>();
    

    Cheers

    Paul

  • Frans de Jong 499 posts 1708 karma points c-trib
    Nov 03, 2019 @ 23:24
    Frans de Jong
    0

    A important remark with this method is that the documenttype alias of your root/home node must be "home" in this case, otherwise this won't work.

    If you don't know the documenttype alias you can always do:

    var homePage = Model.AncestorOrSelf(1);
    
  • Marshall Penn 28 posts 143 karma points
    2 days ago
    Marshall Penn
    0

    The "Home" in Model.AncestorOrSelf<Home>() is the type name, rather than an alias - otherwise it would have quotation marks, surely?

  • john blair 33 posts 195 karma points
    Nov 04, 2019 @ 17:05
    john blair
    0

    The current page is just the model - picked up in the master razor layout. FYI I use the following for the home page, and I also allow a local page header and footer to override the global settings.

     EcHomePage homePage = (EcHomePage)Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias.Equals("ecHomePage"));
    
     IPublishedContent currPage = Model;
    EcGlobalSettings configPage = homePage.Descendant<EcGlobalSettings>();
    // Allow page footer to override global footer.
    EcFooterSection footerSection = currPage.Children<EcPageSettings>().FirstOrDefault()?.Descendant<EcFooterSection>() ?? configPage.Descendant<EcFooterSection>();
    
    // Allow page header to override global header.
    EcHeaderSection headerSection = currPage.Children<EcPageSettings>().FirstOrDefault()?.Descendant<EcHeaderSection>() ?? configPage.Descendant<EcHeaderSection>();
    
Please Sign in or register to post replies

Write your reply to:

Draft