Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kenneth Jørgensen 3 posts 23 karma points
    Jan 22, 2011 @ 01:37
    Kenneth Jørgensen
    0

    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>

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 22, 2011 @ 07:50
    Jonas Eriksson
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft