Copied to clipboard

Flag this post as spam?

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


  • Nicky Christensen 76 posts 166 karma points
    Jan 07, 2014 @ 10:39
    Nicky Christensen
    0

    Link from contentpicker?

    Hey Guys...

    Im running a Umbraco 7.01, and i've created a Razor Macro (Not a partial), and I wanna render a link from a content picker (The contentpicker has the ID of the page, and I want make it to a link), however I cant quite get it to work... Im trying to use Library.NodeById(), but it doens't work? 

    Any ideas? 

     // List planets if visible

        if (planetNodeStart.Children.Where("Visible").Any())

        {

            <div class="planets">

                @foreach (var page in planetNodeStart.Children.Where("Visible"))

                {

                    <div class="planet">

                        @{

                        var node = Library.NodeById(page.planetLink);

                        <a href="@node.Url">

                            @node.Name

                        </a>

                        }

                    </div>

                }

            </div>

        }

  • Nicky Christensen 76 posts 166 karma points
    Jan 07, 2014 @ 10:45
    Nicky Christensen
    0

    Also tried doing this, but still doens't work:

    <div class="planets">

                @foreach (var page in planetNodeStart.Children.Where("Visible"))

                {

                    <div class="planet">

                        @{

                        var node = Model.Library.NodeById(page.planetLink);

                        <a href="@node.Url">

                            @page.Name

                        </a>

                        }

                    </div>

                }

            </div>

  • Nicky Christensen 76 posts 166 karma points
    Jan 07, 2014 @ 11:07
    Nicky Christensen
    100

    Ahhh, found my error, the solution was:

    @foreach (var page in planetNodeStart.Children.Where("Visible"))

                {

                     

                    //If there a link to a module

                    if (page.HasValue("planetLink")){

                        

                        var node = Library.NodeById(page.planetLink);

                        <a href="@node.Url">

                            @page.Name

                        </a>

                    }          

                }

Please Sign in or register to post replies

Write your reply to:

Draft