Developer forum

Forum » Templates » Razor - Get Top Page data (Item)

Razor - Get Top Page data (Item)

Nuno Aguiar
Reply

Hi,

 

How do I get the data of a page (item)?

 

I now we can get the TopPageID, but I need the data of that page. Is there a way to reference a page by ID and get all of the data?

 

Nuno


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Nuno

Something like this:

var page = Dynamicweb.Frontend.Page.FindPage(123);
page.Value("PageMenuText");
page.ID;
page.AreaID;
Votes for this answer: 1
 
Mikkel Ricky
Reply

You can get a Dynamicweb.Frontend.Page (same type as Pageview.Page in Razor) or a Dynamicweb.Content.Page using the Dynamicweb API in Razor:

@Dynamicweb.Frontend.Page.FindPage(pageId)
@Dynamicweb.Content.Page.GetPageById(pageId)

Best regards,
Mikkel

 
Nuno Aguiar
Reply

Hi Nicolai and Mikkel,

 

Great answers both of you. This info should be in the Razor manual ;) Seems like basic info for frontend developers without VisualStudio and/or .NET knowledge

 

Nuno

 
Nuno Aguiar
Reply

Hi Guys,

 

I still can't get this to work. Am I the bug, or is there another :P Check out in attach the template.

 

I cannot get @Dynamicweb.Content.Page.GetPageById(pageId) to work, only FindPage method

I cannot get the TopPageID either, using a hardcoded value for the time being

How will I get the item values (filelds) for this page?

 

Nuno

 
Mikkel Ricky
Reply

Try using it like this:

@{
var topPageId = (int)Pageview.Area.get_Value("AreaFirstActivePage");
var topPage = Dynamicweb.Frontend.Page.FindPage(topPageId);
}

@topPage.AreaID
@topPage.ID
@topPage.get_Value("PageMenuText")

Best regards,
Mikkel

 
Nuno Aguiar
Reply

Hi Mikkel,

 

That worked but not when I need to make a few adjustments. I tried looking into the documentation with no luck :(

What I need is a ParentPage's Item value. This is what I tried, but DW does not tell me where the error is:

 

@{
var parentPageId = (int)Pageview.Page.get_Value("PageParentID");
var parentPage = Dynamicweb.Frontend.Page.FindPage(parentPageId);
}
 
@parentPage.AreaID
@parentPage.ID
@parentPage.get_Value("Item_System_Name")
// The parent Page is an Item (Page as Item) - Does it have any influence in the API?

 

 

Also, how could we know all of the possibilities under "get_Value"?

 

Can you help?

Nuno

 
Mikkel Ricky
Reply
This post has been marked as an answer

Does Dynamicweb report an error or does your code simply not work as intended?

You can get a list of keys for use in get_Value like this:

<pre>
@foreach (System.Collections.DictionaryEntry e in topPage.Values) {
    @: @e.Key: @e.Value
}
</pre>

 

Votes for this answer: 1
 
Nuno Aguiar
Reply

Hi Mikkel,

 

Perfect! We got it now. GREAT!

 

Nuno

 

You must be logged in to post in the forum