This creates an error. Maybe I don't want a macro, but a partial page? There's no foreach... just extracting child nodes and values from the model by id.
Then you just need to amend your code to tack on the profileID - the default of 1 is just an example - you'd probably want to do some more complicated logic here (listing profiles or what have you).
Good point Charles - I read this as a Partial View (Razor) that just needs to display the relevant profile on this page.... I always read Macro as "Partial View", probably a bit dangerous to assume!
And yes, Charles and Steve... I'm thinking this should probably be a partial view, rather than macro. Macros typically use loops, right? No need to loop values on a detail page... just grab values of child nodes.
Which brings me to issue #2. I've tried uQuery and was able to get the parent node name, which is the person's full name. However, for the life of me I can't figure out how to grab child node values.
Below, <p>@bio</p> doesn't throw an error (I'm currently using a macro, but I can change that to partial view):, but <p>@bio.Name</p> does.
@using umbraco;
@using umbraco.NodeFactory;
@using Umbraco.Core.Models;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var id = Request.QueryString["id"];
Node node = uQuery.GetNode(id);
Node bio = node.GetChildNodeByName("bio");
if (node != null)
{
<p>@node.Name</p>
<p>@bio</p>
}
else
{
Response.Redirect("/people.aspx");
}
}
So I have 2 issues:
Passing the ID to the URL without a QS
Getting child node values to show. Willa partial view render razor differently than a macro?
Thanks for the help so far... I pulled my hair out for hours last night getting nowhere. lol
This url has a valid query string and your Request.QueryString["id"] will return 12.
What version of Umbraco are you using? umbraco.MacroEngines.DynamicNodeContext that seems odd to me.
You should not get the nodes by name GetChildNodeByName() this can change and effectively destroys the use of the CMS, you are better of looking up the nodes by docTypeAlais
I think you need to tell us
What you are trying to achieve
What pages you have
Are you using MVC or web forms?
What version of Umbraco
Problem 1: I can't figure out how to get child node values.
Problem 2: Querystrings are bad for SEO, so I'd prefer to use routing values (such as in web.config) to pull the id from the friendly URL, such as www.mysite.com/people/ga/atlanta/joe-blow/12.aspx. NiceUrl doesn't pass the ID, so I guess I'll need to setup a custom routing engine.
Before you get too far into custom routing. Are you sure that you can't achieve what you need by just structuring you Umbraco nodes? How does your data structure look?
Homepage - People - State - City - Dave Somebody - Joe Blow - ....
If it's like the above - then your nodes can serve as pages - no need for clever URL rewriting. Let Umbraco's tree structure dictate the URL and use Partial View macros to list children. For example in the city template create a macro that lists all nodes of doc type "person" below. I'm struggling to see why you need the ID - perhaps we're missing something but you seem to be looking at this with a bit too much of an MVC eye.
As an SEO note (at the risk of getting shot down but SEO specialists..) these days URL variables are not the evil they once were, Google understands them - though I don't think you need them if all you're doing is listing children and linking to them!?!?
if (nodeId == -1) { Response.Redirect("/people.aspx"); }
<p>@personNode.Name</p> }
Works like a champ without having to extract the id from the QS. Yep... I was thinking too much about MVC. ;o)
So now the issue is how to get the child node values from @personNode. Please see the Umbraco node tree above. For example, <longBio /> has a value. How do I parse that from the root node @personNode?
I explained this in the beginning of my post. I know you can get lost reading a lot of code, so sorry for the confusion. :P
I have a .cshtml macro (revised code in my last post) set to view in personProfile.master. I can now get the correct name from the PersonProfile node, but my remaining problem is displaying child node values.
I'm using 6.2.4 within VS 2013. No custom classes, controllers, or MVC views... just docTypes and macros created straight through Umbraco and edited in VS.
I explained this in the beginning of my post. I know you can get lost reading a lot of code, so sorry for the confusion. :P
I have a .cshtml macro (revised code in my last post) set to view in personProfile.master. I can now get the correct name from the PersonProfile node, but my remaining problem is displaying child node values.
I'm using 6.2.4 within VS 2013. No custom classes, controllers, or MVC views... just docTypes and macros created straight through Umbraco and edited in VS.
Homepage - About -People ---- GA --------Atlanta ------------Joe Blow - Contact
What's wrong with try/catch? It's a great way to do a redirect, based on null content (such as someone editing the URL). I'm extracting the path to get the node via the id.
This is more like thinking from a .NET forms approach, rather than MVC. I'm an MVC newbie and my wires are crossed how to get the model using a partial view template rendered in a .master page template.
This is really just a simple profile page where you can display the details (child nodes) of a person. The People page displays a list of people, each of which click to a detail page.
From the most basic level, is there an example set of code somewhere that you can point me to that shows, step by step, how to use masterpages to display partial views or macros that pull the child nodes (remember, I use these to display data) of only 1 particular parent node?
This is an item detail page for a person's profile.
From the most basic level, is there an example set of code somewhere that you can point me to that shows, step by step, how to use masterpages to display partial views or macros that pull the child nodes (remember, I use these to display data) of only 1 particular parent node?
This is an item detail page for a person's profile.
How to create a basic item detail page
Hello,
While I've created many Umbraco macros, I've never created an item details page that filters from a querystring "id" passed.
First, I've created a macro that lists people with friendly URLs like www.mysite.com/people/ga/atlanta/joe-blow.aspx. The link looks like:
It doesn't include the item id in the URL, but I'm using a URL rewrite rule in IIS that I think might extract it, but may be wrong:
Then, I have a .cshtml macro in personProfile.master that I'm not sure how to get the details of that particular person node:
This creates an error. Maybe I don't want a macro, but a partial page? There's no foreach... just extracting child nodes and values from the model by id.
Please help!
Many thanks,
Scott
Hi Scott,
Do you just want to read the URL parameter from the query string? As in, end users will hit www.mysite.com/people/ga/atlanta/joe-blow.aspx?id=123
// page param
int profileId = 1;
if (!int.TryParse(Request.Params["id"], out pageId))
{
profileId= 1;
}
Then you just need to amend your code to tack on the profileID - the default of 1 is just an example - you'd probably want to do some more complicated logic here (listing profiles or what have you).
Scott how are you using this 'marco' Do you mean a view / partial view or a macro you will use in the RTE ect?
Charlie :)
Good point Charles - I read this as a Partial View (Razor) that just needs to display the relevant profile on this page.... I always read Macro as "Partial View", probably a bit dangerous to assume!
The URL should pass the ID without a querystring. NiceURL doesn't seem to include the ID, so...
www.mysite.com/people/ga/atlanta/joe-blow.aspx.
Should really be
www.mysite.com/people/ga/atlanta/joe-blow/12.aspx.
Not sure how to make that change.
And yes, Charles and Steve... I'm thinking this should probably be a partial view, rather than macro. Macros typically use loops, right? No need to loop values on a detail page... just grab values of child nodes.
Which brings me to issue #2. I've tried uQuery and was able to get the parent node name, which is the person's full name. However, for the life of me I can't figure out how to grab child node values.
Below, <p>@bio</p> doesn't throw an error (I'm currently using a macro, but I can change that to partial view):, but <p>@bio.Name</p> does.
So I have 2 issues:
Ha i do the same thing Steve.
Scott i think you / we are a bit lost. What are you actually trying to achieve with this page?
Why do you want the node id on the end of the Url? As Steve says this should be a query string and not stuck on the end of the url
Take a look at http://our.umbraco.org/documentation/reference/templating/macros/ for macros
Take a look at http://www.w3schools.com/aspnet/mvc_intro.asp for MVC
A few problems :)
First is this line:
Request.QueryString["id"];
This is looking for the query string on the URL
so it should be:
www.mysite.com/people/ga/atlanta/joe-blow/?id = 12
This url has a valid query string and your Request.QueryString["id"] will return 12.
What version of Umbraco are you using? umbraco.MacroEngines.DynamicNodeContext that seems odd to me.
You should not get the nodes by name GetChildNodeByName() this can change and effectively destroys the use of the CMS, you are better of looking up the nodes by docTypeAlais
I think you need to tell us
What you are trying to achieve What pages you have Are you using MVC or web forms? What version of Umbraco
Reply back and we will help you out :). Charlie
Charlie,
Sorry about the confusion!
Basically, I want to build an item detail page. Here's a sample of parent/child nodes for each person from umbraco.config:
Problem 1: I can't figure out how to get child node values.
Problem 2: Querystrings are bad for SEO, so I'd prefer to use routing values (such as in web.config) to pull the id from the friendly URL, such as www.mysite.com/people/ga/atlanta/joe-blow/12.aspx. NiceUrl doesn't pass the ID, so I guess I'll need to setup a custom routing engine.
Before you get too far into custom routing. Are you sure that you can't achieve what you need by just structuring you Umbraco nodes? How does your data structure look?
If it's like the above - then your nodes can serve as pages - no need for clever URL rewriting. Let Umbraco's tree structure dictate the URL and use Partial View macros to list children. For example in the city template create a macro that lists all nodes of doc type "person" below. I'm struggling to see why you need the ID - perhaps we're missing something but you seem to be looking at this with a bit too much of an MVC eye.
As an SEO note (at the risk of getting shot down but SEO specialists..) these days URL variables are not the evil they once were, Google understands them - though I don't think you need them if all you're doing is listing children and linking to them!?!?
I just figured the first part out. I can get the parent "PersonProfile" node like this:
Works like a champ without having to extract the id from the QS. Yep... I was thinking too much about MVC. ;o)
So now the issue is how to get the child node values from @personNode. Please see the Umbraco node tree above. For example, <longBio /> has a value. How do I parse that from the root node @personNode?
I agree Steve :). SCOTT SLOW DOWN!
Are you using mvc? The code you have above is it in a view or a partial view?
What version of Umbraco are you using?
Do not write or edit more code, you will go around in circles :).
Also you should not have a try catch block there, that is just wrong :).
Why are you trying to get a node by Path?
Can you show us the content structure laid out like Steve has done above please :).
Also what are the doc types or your nodes?
Charlie :)
Also if its a view you should be using @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Then you can use @Model.GetPropertyValue() and Model.Children things like that :) take a look at:
http://our.umbraco.org/documentation/Reference/Templating/Mvc/
I explained this in the beginning of my post. I know you can get lost reading a lot of code, so sorry for the confusion. :P
I have a .cshtml macro (revised code in my last post) set to view in personProfile.master. I can now get the correct name from the PersonProfile node, but my remaining problem is displaying child node values.
I'm using 6.2.4 within VS 2013. No custom classes, controllers, or MVC views... just docTypes and macros created straight through Umbraco and edited in VS.
Is using the macro as I am ok to do?
I explained this in the beginning of my post. I know you can get lost reading a lot of code, so sorry for the confusion. :P
I have a .cshtml macro (revised code in my last post) set to view in personProfile.master. I can now get the correct name from the PersonProfile node, but my remaining problem is displaying child node values.
I'm using 6.2.4 within VS 2013. No custom classes, controllers, or MVC views... just docTypes and macros created straight through Umbraco and edited in VS.
Is using the macro as I am ok to do?
Sorry we have confusion here. Are you using MVC, because personProfile.Master is webforms?
The reason for asking for the content structure is the macro does not sound like the write thing to be using?
Charlie.
Charlie,
Here's the content structure in Umbraco:
What's wrong with try/catch? It's a great way to do a redirect, based on null content (such as someone editing the URL). I'm extracting the path to get the node via the id.
This is more like thinking from a .NET forms approach, rather than MVC. I'm an MVC newbie and my wires are crossed how to get the model using a partial view template rendered in a .master page template.
Ok so what data do you want to display on the page from those nodes and what are the properties on the nodes?
I am assuming that you have a template on People and when you go to the people page you want that page to display all of the people underneath it?
What is the document types on the Joe Blow node?
Well the problem with the try catch is you are not really trying to do anything and not going to catch anything.
Yours:
@{ int nodeId = -1; try { nodeId = personNode.Id; } catch { }
if (nodeId == -1) { Response.Redirect("/people.aspx"); } }
Mine:
@{
int nodeId = 0; if(personNode!= null && personNode.Id > 0) { Response.Redirect("/people.aspx") } }
On what page is this getting called?
This is really just a simple profile page where you can display the details (child nodes) of a person. The People page displays a list of people, each of which click to a detail page.
Scott could you answer my questions and i will help :).
Charlie
The People page lists people, each of which clicks to a detail page (PeopleProfile template, or PeopleProfile.master).
Ok in your structure what nodes are peopleProfile? What is the document type of peopleProfile.
In the code above is the file .aspx or .cshtml?
Charlie
I must not be explaining this very clearly.
From the most basic level, is there an example set of code somewhere that you can point me to that shows, step by step, how to use masterpages to display partial views or macros that pull the child nodes (remember, I use these to display data) of only 1 particular parent node?
This is an item detail page for a person's profile.
I must not be explaining this very clearly.
From the most basic level, is there an example set of code somewhere that you can point me to that shows, step by step, how to use masterpages to display partial views or macros that pull the child nodes (remember, I use these to display data) of only 1 particular parent node?
This is an item detail page for a person's profile.
Nodes called "PersonProfile" are the parent nodes.
Can you kindly look at my code?
Hi Its not that explaining well i am trying but i need answers to the questions i ask so i can help :)
Like are you using MVC or WebForms (sounds like you are using both)
What are the document types? Do you know what they are?
Charlie
Sure i will take a look for you
is working on a reply...