Copied to clipboard

Flag this post as spam?

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


  • bh 175 posts 597 karma points
    Mar 08, 2019 @ 13:49
    bh
    0

    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 4838 posts 14286 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 175 posts 597 karma points
    Mar 08, 2019 @ 14:56
    bh
    0

    Many thanks @SebastiaanJanssen!

  • Anders Brohus 159 posts 397 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 480 posts 1648 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 159 posts 397 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 480 posts 1648 karma points c-trib
    Mar 09, 2019 @ 20:31
    Frans de Jong
    1

    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 159 posts 397 karma points
    Mar 09, 2019 @ 20:33
    Anders Brohus
    0

    Nice thanks!

    It works with

        var rootNode = Model.Root() as Frontpage;
    

    Thanks alot! :)

  • Tom 709 posts 946 karma points
    6 days ago
    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 480 posts 1648 karma points c-trib
    6 days ago
    Frans de Jong
    0

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

  • Tom 709 posts 946 karma points
    6 days ago
    Tom
    0

    Thanks Frans, Currently PureLive

  • Frans de Jong 480 posts 1648 karma points c-trib
    6 days ago
    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.

Please Sign in or register to post replies

Write your reply to:

Draft