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
    Jul 03, 2013 @ 13:09
    Michael
    0

    Changing values based on ID

    Hi there

    Just started on my first razor macro and ran into a problem.

    The macro that needs to change some values of my button (link and text) based on the top level node ID. Not quite sure what's wrong, but I think it must be my if statements.

    My code looks like this:

    @{
      Session["sideNavn"] = @Model.Name;
      int sideId = @Model.AncestorOrSelf.Id;
    }
    @{
      var btnLink = "";
      var btnTekst = "";
      if(sideId == 1103)
      {
        btnLink = "/link1";
        btnTekst = "UK text";
      }
      else if(sideId == 1105)
      {
        btnLink = "/link2";
        btnTekst = "German text";
      }
      else
      {
        btnLink = "/link3";
        btnTekst = "Danish text";
      }
    }
    <form action="@btnLink" method="post">
      <input id="produktBtn" class="produktBtn" type="submit" value="@btnTekst" />
    </form>

    Any help or pointers would be great :)

    /Michael

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 03, 2013 @ 13:23
    Fuji Kusaka
    1

    Hi Michael,

    From the code your posted seems like you have a multilingual website right ? If so why not make use of culture info ?

    So if its gets CultureInfo Fr, De, Dk it displays something related to it.

     

  • Michael 63 posts 211 karma points
    Jul 11, 2013 @ 09:40
    Michael
    0

    Hi Fuji

    Thx for the reply. Yes it is multilingual, so I guess that would make more sense yes :) But its not something I have that much experience with.

    I will look into it ;)

    Just go get the hang of this Razor, is my code above correct, razor-wise i mean? :)

     

    /Michael

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jul 11, 2013 @ 12:39
    Jeroen Breuer
    0

    Looks like you're still using the old Razor. Might be good to read this: http://our.umbraco.org/forum/developers/razor/43007-Razor-Docs-Book#comment155105

    Jeroen

  • Michael 63 posts 211 karma points
    Jul 11, 2013 @ 14:29
    Michael
    100

    Hi Jeroen

    Thx for the link and making me aware of my outdated ways :)

    In regards to my problem I made a quick and dirty dirty solution :P (out of time and the client does not have the need for additional languages)

    The code that fixed it is:

    @{
      Session["sideNavn"] = @Model.Name;
      var sproglagNavn = @Model.AncestorOrSelf("Forside");
      string btnSprog = @umbraco.library.GetDictionaryItem("Produktknap");
    }
    @{
      var btnLink = "";
      var btnTekst = btnSprog;
      if(sproglagNavn.Name == "Home")
      {
        btnLink = "EN link";
      }
      else if(sproglagNavn.Name == "Start")
      {
        btnLink = "DE link";
      }
      else
      {
        btnLink = "DK link";
      }
    }
    <form action="@btnLink" method="post">
      <input id="produktBtn" class="produktBtn" type="submit" value="@btnTekst" />
    </form>

    In case it might help someone or at the very least just to mark it as resolved :)

    /Michael

Please Sign in or register to post replies

Write your reply to:

Draft