Copied to clipboard

Flag this post as spam?

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


  • Ulrik Nedergaard 44 posts 175 karma points
    Apr 30, 2011 @ 11:26
    Ulrik Nedergaard
    0

    Error with formatting

    Hi

    I'm trying to implemente a breadcrumb with the following code : 

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
      
      @foreach(var level in @Model.Ancestors().Where("Visible"))
      {
      &nbsp;&raquo;&nbsp;    <---- Does NOT work
      <href="@level.Url">@level.Name</a>
      }
      &nbsp;&raquo;&nbsp; <---- Works fine
      @Model.Name
    </umbraco:Macro>

    My second &nbsp;&raquo;&nbsp; works as intended but the first one fails.

    Could anyone explain why? By the way, i'm used to work in vb so this c-stuff is new to me :)

    / Ulrik 

  • Ulrik Nedergaard 44 posts 175 karma points
    Apr 30, 2011 @ 11:33
    Ulrik Nedergaard
    0

    Whoops - something dissapeared when I posted.

    &raquo;     should be     &nbsp;&raquo;&nbsp;

  • Jonas Eriksson 930 posts 1825 karma points
    Apr 30, 2011 @ 12:41
    Jonas Eriksson
    0

    Hi, in these cases it's usually good to wrap the html in <text> tags,

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
     
      @foreach(var level in @Model.Ancestors().Where("Visible"))
      {
       <text>&nbsp;&raquo;&nbsp;</text>     <---- Add <text>
      <a href="@level.Url">@level.Name</a>
      }
       &raquo;
      @Model.Name
    </umbraco:Macro>

     

  • Ulrik Nedergaard 44 posts 175 karma points
    Apr 30, 2011 @ 12:54
    Ulrik Nedergaard
    0

    Thanks for the response Jonas. Sounds logical :)

    Tried it but got this error : 

    The 'text' property of 'umbraco.presentation.templateControls.Macro' cannot be declared as an inner property, it must be declared as an attribute.

  • Jonas Eriksson 930 posts 1825 karma points
    Apr 30, 2011 @ 13:06
    Jonas Eriksson
    0

    ouch, yes - reminds me, the <text> tag does not work in razor direct in a template ( http://umbraco.codeplex.com/workitem/30098 )... you will need to make a macro of your code to make it work. Might be other workarounds also, but I would recommend a separate macro.

  • Ulrik Nedergaard 44 posts 175 karma points
    Apr 30, 2011 @ 13:08
    Ulrik Nedergaard
    0

    Aaaah. Great - I'll do that.

    Thanks again 

  • Jonas Eriksson 930 posts 1825 karma points
    Apr 30, 2011 @ 13:39
    Jonas Eriksson
    1

    Another alternative : add the @: before the markup instead of <text>. Shorter syntax, and should work in fine template too.

    @foreach(var level in @Model.Ancestors().Where("Visible"))
    {
     @:&nbsp&raquo;&nbsp     <---- Add @:

  • Ulrik Nedergaard 44 posts 175 karma points
    Apr 30, 2011 @ 14:35
    Ulrik Nedergaard
    0

    Cool. Worked perfectly - so thats what I'm using now :)

Please Sign in or register to post replies

Write your reply to:

Draft