Developer forum

Forum » Feature requests » Access parent item values from module

Access parent item values from module

Morten Fink Eriksen
Reply

Hi 

I know that we can access global area item values in module, but unless i am missing something this is not possible for paragraph/itemtype item values right now. So i would really like to suggest this as a feature, since modules and paragraphs/itemtypes are closely related anyway this makes sense in my opinion.

P.S If i am missing something in regards to accessing individual itemtype values from modules please respond :)


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Morten

If you have a module (ContentModule base class), you can do like this:

Dynamicweb.Content.Paragraph p = Dynamicweb.Content.Paragraph.GetParagraph(this.ParagraphRow);
Dynamicweb.Content.Items.Queries.Repository repo = new Dynamicweb.Content.Items.Queries.Repository(p.ItemType);
dynamic item = repo.SelectById(p.ItemId);

That will give you the item instance from that paragraph.

You can also do

Pageview.Current().Page.Item

if it is an item based page...

BR Nicolai

 
Morten Fink Eriksen
Reply

How about getting the value via razor, say from a productlist template? is this possible.. im getting errors when trying to use this code in the ecom module.

 
Morten Bengtson
Reply
This post has been marked as an answer

In Razor, you can do something like this:

@functions{

    Dynamicweb.Content.Items.Item GetCurrentParagraphItem()
    {
        var paragraph = this.Pageview.CurrentParagraph;
        var item = Dynamicweb.Content.Items.ItemManager.Storage.GetById(paragraph.ItemType, paragraph.ItemId);
        return item;
    }
}

@{
    var item = GetCurrentParagraphItem();
}

<div>@item["MyField"]</div>
Votes for this answer: 1
 
Morten Fink Eriksen
Reply

Ahhh thank you Morten.. just what i was looking for :)