Copied to clipboard

Flag this post as spam?

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


  • Linden Koppejan 15 posts 165 karma points
    Jan 11, 2023 @ 09:01
    Linden Koppejan
    0

    Get the Page of BlockGridItem

    Hello There,

    I'm currently using the Block Grid Edior and I have a Block which doesn't have and Properties.

    I have Projects as a Doctype where information is stored and the blockGrid is added.

    Now I want to render the informations which are on Projects in the Block but I have to get them first.

    Doest anyone know how to get the Parent or the Page where the block is used, inside of the Blocks view?

  • Andrey Karandashov 23 posts 215 karma points c-trib
    Jan 11, 2023 @ 11:49
    Andrey Karandashov
    100

    You just can get a current page inside view using this code:

    umbracoContextAccessor?.GetRequiredUmbracoContext()
                        ?.PublishedRequest
                        ?.PublishedContent
    

    umbracoContextAccessor is instance of IUmbracoContextAccessor. This code works for Umbraco 10, but I think it's the same for 9 or 11.

    If you render block on a page, you will get actual page where it's rendered.

  • Linden Koppejan 15 posts 165 karma points
    Feb 09, 2023 @ 15:50
    Linden Koppejan
    0

    Thanks a lot for your answer

    I solved it with ViewData and passed the Model from the view to the Block :)

    It worked too, but your soltion would have been way nicer!

    Im again working on a site and I hva an different question posted here: https://our.umbraco.com/forum/using-umbraco-and-getting-started/111176-umbraco-block-grid-get-parent-of-blockgridarea

    Maybe you could have a look into it?

    You rock thanks a lot!

  • Liam Dilley 156 posts 382 karma points
    May 15, 2023 @ 06:26
    Liam Dilley
    2

    You do not need to do that much work. You can simply use...

    var currentPage = Umbraco.AssignedContentItem;
    
Please Sign in or register to post replies

Write your reply to:

Draft