Copied to clipboard

Flag this post as spam?

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


  • Jeroen Oostwouder 104 posts 300 karma points
    Jun 01, 2023 @ 07:30
    Jeroen Oostwouder
    0

    Blockgrid: get the grid-containing-node from a block-view

    Hi there,

    I have a block-view (if that's the correct name) that renders some content within the block-grid.

    This view needs to display some data from a fixed Settings-node in the tree. I have a extension-method on IPublishedContent to get to this Settings-node. But how do I get the node that contains the grid?

    I tried using Umbraco.ContentAtXPath("//Settings") but this only works for the first node of type Settings in the tree.

    So if I have multiple Home-nodes (each with a Settings-node underneath) I always get the Settings-node of the first Home-node.

    Is it possible to get the current node I'm on, within the block-view? Or do I need to extend some of the grid-render-functions to pass the node along in the viewbag?

  • Ambert van Unen 175 posts 819 karma points c-trib
    Jun 01, 2023 @ 08:02
    Ambert van Unen
    0

    Cant you get the currentPage from the umbracoContext ? Then you can also get the settings from the current site using something like AncestorOrSelf().OfType

  • Jeroen Oostwouder 104 posts 300 karma points
    Jun 01, 2023 @ 08:16
    Jeroen Oostwouder
    0

    I do seem to have an UmbracoContext object, but I can't seem to figure out how to get the currentPage out of it. UmbracoContext.Content returns an IPublishedContentCache?.

    edit:

    I've triedUmbracoContext.Content.GetAtRoot() but that just returns all root-nodes.

  • Jeroen Oostwouder 104 posts 300 karma points
    Jun 01, 2023 @ 11:13
    Jeroen Oostwouder
    100

    I found it. I can get the parent page via: Umbraco.AssignedContentItem

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies