I am using Umbraco CMS (Version 4.11.9) and facing a problem in accessing the Contact us page using the AncestorOrSelf method. I have tried to explain it by example.
- Content
-- Home (level = 1)
-- About Us (level = 2)
-- Contact Us (level = 2)
-- News Area (level = 2)
-- News Item 1 (level = 3)
-- News Item 2 (level = 3)
-- Other Node (level = 1)
By using Model.Content.AncestorOrSelf(1) I am getting the Other Node (level = 1 as in example).
How could I get the contact us page which is under Home level?
So your case is that you only want the contact us page. Did the page have it´s own document type or did it use a common for textpage e.g If the uses a common one like text page, then you can request a page by it´s id. The down side with this is if you delete the page and created it again, it will get a new id.
Actually in my project i have few pages (like Contact us) to show in footer. In Content => properties => Include In Footer Navigation property is set checked.
Now when the master page loads and if iam under Home(as in the Example) i can access the Contact Us by using
Model.Content.AncestorOrSelf(1).
But when Model is OtherNode(level =1)(as in the Example). I could not Get the Contact Us Page.
If you try writing Model.Content.AncestorOrSelf(1).Count do you then get 1 or 2 returned? If you get 2 returned you might be able to do someting like Model.Content.AncestorOrSelf(1).First(), which I think maybe return the Home node and then you should be able to query the children - But I have not tested this so not sure it works.
But otherwise it might be worth considering adding a content picker or multiple node picker to the "Other node" document type so you can pick the "Contact us" page from the home node and then use something like @Mode.Content.GetPropertyValue("pickerPropertyAlias"); - Which will probably give you and id you'll need to lookup in order to get the content you desire.
Thanks Jan.Thank you vey much for pointing me to right direction . your third option was useful for me. I have replied you thrice earlier also but unfortunatily my reply was not updating. Thanks once again.
One more question i need to create a view which admin can access only. its a public site having number of members. Admin need the list of all members. Should i have to create one more login page for user to authenticate and then navigate to member list page.
Just to be clear - The view you're talking about is going to be part of the website, not the Umbraco backoffice, right?
If so then in the "Member" section you can use member groups to differentiate the types of members your site can have. Then you can create an "Admin" group and a "Regular" group and then on each member you can assign what groups the different members should be a part of.
Then in the "Content" section you can right click a node and choose "Public access". Not you can add, which member groups should be allowed access to particular nodes.
If you set it up on a branch of nodes you can overwrite the public access setting for a specific child-node so it's only accessible for administrators.
In your view you can check whether a member has access to a view/page or not by adding a check for .HasAccess().
I hope this answers your question and that I understood it correctly :)
It is having only "Members" under "Member Group". if i create one more child as "Admin" under "Member Group" will it affect the functionality of the "Members" which is already there. Because it is have lot of member already there.
Secondly if i create one more child as "Admin" under "Member Group" . Then the actual back office admin has to register from here. And i have to authenticate him as a member?.
Sorry may be i am asking wrong questions. but please reply.
I don't mind that you ask many questions - I'm just happy to help and will do my best to provide as good answers that I possibly can - The tone in here is much more friendly than other forums so don't by shy to ask anything! :)
But just to be clear - You just need to add another group so you can assign a member to the "Admin" group. Unless you need to have some Admin specific properties on the member type you don't need to create a new member type. So you should be able to just create the "Admin" group and then add members to this group to make them administrators - Does that make sense?
Not sure what you mean by the second question? How are members currently registered in your backoffice? Is it done manually?
I am newbie in umbraco. Please help
I am using Umbraco CMS (Version 4.11.9) and facing a problem in accessing the Contact us page using the
AncestorOrSelf
method. I have tried to explain it by example.By using
Model.Content.AncestorOrSelf(1)
I am getting theOther Node
(level = 1 as in example).How could I get the contact us page which is under Home level?
Hi parikshit and welcome to our :-)
So your case is that you only want the contact us page. Did the page have it´s own document type or did it use a common for textpage e.g If the uses a common one like text page, then you can request a page by it´s id. The down side with this is if you delete the page and created it again, it will get a new id.
https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#TypedContent%28intid%29
Hope this helps, if you get any other questions to this topic then don't hesitate to ask again.
/Dennis
Hello Dennis,
Thanks for responding.
Actually in my project i have few pages (like Contact us) to show in footer. In Content => properties => Include In Footer Navigation property is set checked.
Now when the master page loads and if iam under Home(as in the Example) i can access the Contact Us by using
Model.Content.AncestorOrSelf(1).
But when Model is OtherNode(level =1)(as in the Example). I could not Get the Contact Us Page.
Hi parikshit and welcome to our :)
If you try writing
Model.Content.AncestorOrSelf(1).Count
do you then get 1 or 2 returned? If you get 2 returned you might be able to do someting likeModel.Content.AncestorOrSelf(1).First()
, which I think maybe return the Home node and then you should be able to query the children - But I have not tested this so not sure it works.But otherwise it might be worth considering adding a content picker or multiple node picker to the "Other node" document type so you can pick the "Contact us" page from the home node and then use something like
@Mode.Content.GetPropertyValue("pickerPropertyAlias");
- Which will probably give you and id you'll need to lookup in order to get the content you desire.I hope this helps.
/Jan
Thanks Jan.Thank you vey much for pointing me to right direction . your third option was useful for me. I have replied you thrice earlier also but unfortunatily my reply was not updating. Thanks once again.
Hi Parikshit
You're very welcome - Happy that I could help.
Yeah the forum is a bit quirky unfortunately - But in the near future there will be a re-launch so things come much more up to date.
Happy coding :)
/Jan
Hello Jan,
One more question i need to create a view which admin can access only. its a public site having number of members. Admin need the list of all members. Should i have to create one more login page for user to authenticate and then navigate to member list page.
Hi Parikshit
Just to be clear - The view you're talking about is going to be part of the website, not the Umbraco backoffice, right?
If so then in the "Member" section you can use member groups to differentiate the types of members your site can have. Then you can create an "Admin" group and a "Regular" group and then on each member you can assign what groups the different members should be a part of.
Then in the "Content" section you can right click a node and choose "Public access". Not you can add, which member groups should be allowed access to particular nodes.
If you set it up on a branch of nodes you can overwrite the public access setting for a specific child-node so it's only accessible for administrators.
In your view you can check whether a member has access to a view/page or not by adding a check for .HasAccess().
I hope this answers your question and that I understood it correctly :)
/Jan
Hello Jan,
Thanks for quick reply.
My back office Members screen is as follows:
Members
----Members
----Member Groups
--------Members
----Member Types
--------Member
--------Admin
It is having only "Members" under "Member Group". if i create one more child as "Admin" under "Member Group" will it affect the functionality of the "Members" which is already there. Because it is have lot of member already there.
Secondly if i create one more child as "Admin" under "Member Group" . Then the actual back office admin has to register from here. And i have to authenticate him as a member?.
Sorry may be i am asking wrong questions. but please reply.
Thanks in advance
Hi Parikshit
I don't mind that you ask many questions - I'm just happy to help and will do my best to provide as good answers that I possibly can - The tone in here is much more friendly than other forums so don't by shy to ask anything! :)
But just to be clear - You just need to add another group so you can assign a member to the "Admin" group. Unless you need to have some Admin specific properties on the member type you don't need to create a new member type. So you should be able to just create the "Admin" group and then add members to this group to make them administrators - Does that make sense?
Not sure what you mean by the second question? How are members currently registered in your backoffice? Is it done manually?
/Jan
is working on a reply...