Copied to clipboard

Flag this post as spam?

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


  • Sascha 4 posts 24 karma points
    Aug 05, 2012 @ 13:21
    Sascha
    0

    My first macro :)

    Hy :)

    I have a checkbox property for the user.

    On the Content Section, the User has a Checkbox where he can check if he wants to have the Meta Robots String included in the Output page, else it gets the "robots No Follow" html string in the head section.

    <meta name="robots" content="index, follow">

    The Propertie Alias = metaRobotsFollow

    I added this code in the masterpagetemplate, but it dont work :(

     <umbraco:Macro runat="server" language="cshtml">
          @using umbraco.MacroEngines
          @inherits umbraco.MacroEngines.DynamicNodeContext
          @{
          
            if (model.metaRobotsFollow.Value == '1')
            {
            <meta name="robots" content="index, follow">
            }
            else
            {
            <meta name="robots" content="index, nofollow">
            }
          
          }
        </umbraco:Macro>

  • Sascha 4 posts 24 karma points
    Aug 05, 2012 @ 15:32
    Sascha
    0

    Got it working now :) after reading a few discussions online, i made this one and it works perfectly :)

     

    @{
      if (@CurrentModel.HasProperty("metaRobotsFollow"))
      {
          string value = CurrentModel.GetProperty("metaRobotsFollow").Value;
          string robotsfollow = "";
            if (value == "1")
             {
              robotsfollow = "<meta name='robots' content='index, follow' />";
              }
             else
             {
              robotsfollow = "<meta name='robots' content='index, nofollow' />";
              }
           @Html.Raw(robotsfollow);
      }
    }

  • MartinB 411 posts 512 karma points
    Aug 05, 2012 @ 20:52
    MartinB
    0

    Hi Sacha

    Not knowing what kind of system you're doing, wouldn't it be better to have it the other way around (check to exclude rather than include). Or is it sensitive data?

    Aslo, you can mark you own reply as the solution, which would help others in the futere.

    Have a nice day.

Please Sign in or register to post replies

Write your reply to:

Draft