Hi guys,
This one should be fairly easy.
If I have Page object in API like this: var page = Dynamicweb.Content.Page.GetPageById(Convert.ToInt32(PageID));
how to I get its "PageShowInLegend" value?
/Dmitrij
Hi guys,
This one should be fairly easy.
If I have Page object in API like this: var page = Dynamicweb.Content.Page.GetPageById(Convert.ToInt32(PageID));
how to I get its "PageShowInLegend" value?
/Dmitrij
First I thought it should be something like this:
page.Values["pageshowinlegend"]
But instead I am getting Razor error
Dynamicweb.Content.Page' does not contain a definition for 'Values' and no extension method 'Values' accepting a first argument of type...
Any suggestions?
/Dmitrij
Hi Dmitrij
There is a Frontend.Page and a Content.Page. Content.Page has a property for that: http://developer.dynamicweb.com/api8/#Dynamicweb~Dynamicweb.Content.Page~ShowInLegend.html
If you are in a template, you can do this: Dynamicweb.Frontend.PageView.Current().Page.get_Value("PageShowInLegend");
Hi Nicolai,
Thanks for the answer, well that's the main issue, in this particular case, I have a page as an object, and can't call "Pageview" in this case.
Like in this example here:
@helper RenderNavigation(System.Collections.Hashtable pageCollection, int parent = 0) { var pages = pageCollection.Values.Cast<Dynamicweb.Frontend.Page>() .Where(p => (int)p.AreaID == Dynamicweb.Frontend.PageView.Current().Area.ID && (bool)p.Values["pageactive"] && (int)p.Values["pageparentpageid"] == parent && !(bool)p.Values["pagehidden"] && (DateTime)p.Values["pageactivefrom"] < DateTime.Now && (DateTime)p.Values["pageactiveto"] > DateTime.Now && (bool)Dynamicweb.Security.IsCurrentUserAllowed(p)) .OrderBy(p => (int)p.Values["pagesort"]); foreach (var page in pages) { <li> @page.Values["pagemenutext"] @if (page.Children.Count > 0) { <ul> @RenderNavigation(pageCollection, page.ID) </ul> } </li> } }
You have a way to access this attribute, along with other attributes.
But when you are accessing page object viaØ
var page = Dynamicweb.Content.Page.GetPageById(Convert.ToInt32(PageID));
- you suddenly don't have Values on Get_Value method.
Well atleast according to this, can't seem to find a way.
http://developer.dynamicweb-cms.com/api8/#Dynamicweb~Dynamicweb.Content.Page_members.html
/Dmitrij
Hi Dmitrij
Frontend.Page has the get_Value and Content.Page does not. As I wrote. So Dynamicweb.Content.Page.GetPageById(Convert.ToInt32(PageID)); does not have get_Value because it is Content.Page and not Frontend.Page.
In your code you should be able to use !(bool)p.Values["PageShowInLegend"]. You p is a Frontend.Page object.
And since your code is running in the context of the frontend, you can use PageView. But in this situation it does not make sense, because PageView.Current().Page contains the page being viewed and you need the property for each page in the navigation.
Hi Nicolai,
Thanks for your patience :-) And sorry if I missunderstand something, but just bare with me, and we will get to the buttom of this :-)
As you wrote:
And since your code is running in the context of the frontend, you can use PageView
That is not what I wrote, I am not in the page context, therefore I can't use Pageview.
In order to make it a bit easyer, this is my helper method:
@helper RenderParentNavigation(Dynamicweb.Content.Page page) { var parent = page.Parent; if (page.Parent != null) { <text>@RenderParentNavigation(parent)</text> } else { <text><li><a href="/">@Translate("Breadcrumb.Root")</a></li></text> } string bread_pageHref = string.Format("/Default.aspx?id={0}", page.ID.ToString()); if ((bool)page.Values["PageShowInLegend"]) { <li><a href="@bread_pageHref">@page.MenuText</a></li> } }
Hope this brings some light of what I am trying to achieve here.
Eventually:
(bool)page.Values["PageShowInLegend"]
Causes an error, obviously.
'Dynamicweb.Content.Page' does not contain a definition for 'Values' and no extension method 'Values' accepting a first argument of type 'Dynamicweb.Content.Page' could be found (are you missing a using directive or an assembly reference?)
Hi Dmitrij
You keep mixing up Content.Page with Frontend.Page is making me nervous :-). It is 2 very different types...
Anyway - you are creating a navigation, but are not in the context of a pageview (in the frontend)?
That is not a good thing, since showinlegend in frontend context can have another value than it does on its content representation. So you need to tell me exactly what you want to achieve and in what context.
Or try this one: bool showInLegend = Dynamicweb.Input.FormatBoolean(Dynamicweb.Frontend.Page.FindPage(123).get_Value("PageShowInLegend"));
Hi Nicolai :)
You keep mixing up Content.Page with Frontend.Page is making me nervous :-). It is 2 very different types...
Sorry, but I am very thankfull for your patience! And for clearing this one out! :-)) I will try to see what I can do with Fronttpage.Page at once.
Anyway - you are creating a navigation, but are not in the context of a pageview (in the frontend)?
That's right, I am not in the context of a pageview.
That is not a good thing, since showinlegend in frontend context can have another value than it does on its content representation. So you need to tell me exactly what you want to achieve and in what context.
Basic goal is to be able to track "hide in breadcrumb" checkbox under page properties in /Admin.
While I am trying to check it via @helper method like one I posted in my previous post.
Since it's helper, all it knows is that I am feeding it - in this case it acceps an object of class "Dynamicweb.Content.Page".
Therefore the goal is to be able to check "hide in breadcrumb" true or false for that object that was just passed to a helper.
I will try your code snippet, and will try looking if I can find what I needed with Frontend.page :-)
/Cheers,
Dmitrij
Hi Nicolai,
Thanks for help! :)
bool showInLegend = Dynamicweb.Input.FormatBoolean(Dynamicweb.Frontend.Page.FindPage(123).get_Value("PageShowInLegend"));
worked very well! :)
/Dmitrij
Hi Nicolai,
Thanks for help! :)
bool showInLegend = Dynamicweb.Input.FormatBoolean(Dynamicweb.Frontend.Page.FindPage(123).get_Value("PageShowInLegend"));
worked very well! :)
/Dmitrij
You must be logged in to post in the forum