hi i am making a site where i on my doctype has a proparty call title how do i access that from from razor i will like to replace c.name with title
@using umbraco.NodeFactory @helper main(int nodeid) { @{ Node n = new Node(nodeid); if (n.Children.Count>0) { @foreach (Node c in n.Children) { <li class="top"><a href="@umbraco.library.NiceUrl(c.Id)" class="top_link"><span>@c.Name</span></a>@Navnote(c.Id)</li>}}}} @helper Navnote(int nodeid) { @{ Node n = new Node(nodeid); if (n.Children.Count>0) { <ul class="sub"> @foreach (Node c in n.Children) { <li><a href="@umbraco.library.NiceUrl(c.Id)">@c.Name @subnote(c.Id)</a></li>}</ul>}}} @helper subnote(int nodeid) { @{ Node n = new Node(nodeid); if (n.Children.Count>0) { <ul> @foreach (Node c in n.Children) { <li><a href="@umbraco.library.NiceUrl(c.Id)">@c.Name@subnote(c.Id)</a></li>}</ul>}}} <ul id="nav"> @main(1064) </ul>
razor proparty
hi i am making a site where i on my doctype has a proparty call title how do i access that from from razor i will like to replace c.name with title
@using umbraco.NodeFactory
@helper main(int nodeid) {
@{
Node n = new Node(nodeid);
if (n.Children.Count>0) {
@foreach (Node c in n.Children) {
<li class="top"><a href="@umbraco.library.NiceUrl(c.Id)" class="top_link"><span>@c.Name</span></a>@Navnote(c.Id)</li>}}}}
@helper Navnote(int nodeid) {
@{
Node n = new Node(nodeid);
if (n.Children.Count>0) {
<ul class="sub">
@foreach (Node c in n.Children) {
<li><a href="@umbraco.library.NiceUrl(c.Id)">@c.Name @subnote(c.Id)</a></li>}</ul>}}}
@helper subnote(int nodeid) {
@{
Node n = new Node(nodeid);
if (n.Children.Count>0) {
<ul>
@foreach (Node c in n.Children) {
<li><a href="@umbraco.library.NiceUrl(c.Id)">@c.Name@subnote(c.Id)</a></li>}</ul>}}}
<ul id="nav">
@main(1064)
</ul>
Hi!
When using Node you would need to use the c.GetValue(propertyname).Value
If you are looping nodes that may or may not have that property you would need to check for nulls also on c.GetValue(propertyname)
I'd also advice you to look at the uComponents.uQuery Node Extension methods (like on the last posts in this thread http://our.umbraco.org/forum/developers/api-questions/16034-Razor-@helper-in-Umbraco )
(You only need to add uComponents package to be able to use uQuery).
Regards
Jonas
is working on a reply...