Copied to clipboard

Flag this post as spam?

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


  • Michael 63 posts 211 karma points
    Jun 11, 2014 @ 11:31
    Michael
    0

    Menu not displaying macro parameter value

    Hi guys

    I am working a razor menu. The idea is that the client manually puts the menu on each language homepage(When I get the macro container to work :P).

    I have to parameters they need to supply when inserting. The place to start the menu and the name of the homepage. The source parameter works fine. The frontPage parameter renders nothing and no errors.

    My code looks like this:

    @{
      var startNodeID = Umbraco.Content(Model.MacroParameters["source"]);
      var homePage = Umbraco.Content(Model.MacroParameters["frontPage"]);
    }

    <ul>
      <li><a href="@startNodeID.Url">@homePage</a></li>
      @foreach (var page in startNodeID.Children.Where("Visible"))
      {
        <li class="@(page.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
          <a href="@page.Url">@page.Name</a>
          @* -- lvl 2 -- *@
          @if (page.Tekstside.Any())
            {
            <ul>
              @foreach (var subpage in page.Tekstside.Where("Visible"))
              {
                <li class="@(subpage.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
                  <a href="@subpage.Url">@subpage.Name</a>
                </li>
              }
            </ul>
            }
        </li>
      }
    </ul>

    Any ideas on why I get no text?

     

    /Michael

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 16, 2014 @ 13:41
    Steve Morgan
    0

    Try 

    <li><a href="@startNodeID.Url">@homePage.Name</a></li>
  • Michael 63 posts 211 karma points
    Jun 16, 2014 @ 13:58
    Michael
    0

    No luck :(

    Hmmm

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 16, 2014 @ 15:46
    Steve Morgan
    0

    Have you checked that you've got the correct case in the Parameter name (both on the Macro and where it's inserted in the Template?!). 

  • Charles Afford 1163 posts 1709 karma points
    Jun 16, 2014 @ 21:05
    Charles Afford
    0

    Thats a good shout :).  I would guess its going to be a parameter name?  What is the functionality you are trying to acheive?

  • Michael 63 posts 211 karma points
    Jun 17, 2014 @ 07:54
    Michael
    0

    Hi guys

    I have checked the alias on both the macro and in the code. Both the same.

    The menu is inserted with the macrocontainer like this in my template:

    <div class="menuBar">@Html.Raw(umbraco.library.RenderMacroContent(CurrentPage.indsaetMenu, CurrentPage.Id))</div>

    The idea is that you insert the menu on each language homepage and tell it where to start and the name of the frontpage it needs to render.

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 17, 2014 @ 09:25
    Steve Morgan
    0

    What version of Umbraco are you using?

    This works for me in 7.1.4

    @Umbraco.RenderMacro("TestNavigation", new {source=CurrentPage.indsaetMenu, frontPage=CurrentPage.Id})
  • Michael 63 posts 211 karma points
    Jun 17, 2014 @ 09:54
    Michael
    0

    In am on 7.1.4 as well :)

    When I use your code I get the name of the frontpage rendered. But not the value entered in the textbox macro parameter.

    My site structure looks like this:

    Danish homepage

    - Subpages

    Language version

    - Language homepage

    -- Subpages

     

    On each new homepage the client inserts the menu with the macro container by filling out the contentpicker and the textbox with the custom name. The reason why I need the textbox parameter is because the nodes are named something like EN for english and DE for german and so on.

    But in the menu I want them to enter something like Home, Start or Forside. So currentpage is not an option.

    By the way, thank you very much for all the help :)

     

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jun 17, 2014 @ 12:41
    Steve Morgan
    100

    Ahhh! Well that's easy then!   Your problem is using Umbraco.Content() for text fields - this is only for load an Umbraco content node (passing in the ID. To just get the text value use Model.MacroParameters["frontPage"] without that method - I'd also rename startNodeID as it's not the ID - it's the actual node content.

     

        var startNode = Umbraco.Content(Model.MacroParameters["source"]);  @* get an umbraco node from a picker *@
         var homePage = Model.MacroParameters["frontPage"]; @* text value *@

    Hope that gets you there.

  • Michael 63 posts 211 karma points
    Jun 17, 2014 @ 12:55
    Michael
    0

    That did the trick.

    Will remember that in the future, and yeah renaming to startNode sounds like a good idea :)

    Thank you kind sir! :D

     

    /Michael

Please Sign in or register to post replies

Write your reply to:

Draft