Copied to clipboard

Flag this post as spam?

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


  • AlessandroDM 21 posts 122 karma points
    Nov 06, 2017 @ 19:22
    AlessandroDM
    0

    Layout Dilemma: Can I use "IF" in razor sintax to provide different HTML?

    Hello there, I'm wondering how to manage different document type for same page. I mean, I would like to be able to create different layouts options (so I create different DOCUMENT TYPES) and in my HTML put an IF marker to use the correct layout I planned. This because I would like to cycle all the children of a section and generate the HTML following the order provided in the content side (where one can have 2 images instead of 3, ecc...).

    Thank you, sorry for my bad english

  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Nov 06, 2017 @ 20:56
    Søren Kottal
    102

    Hi Alessandro

    Yes, you can do like this

    @foreach (var child in Model.Content.Children())
    {
    
      if (child.DocumentTypeAlias == "doctype1") {
        <div class="doctype1">content here</div>
      }
      else if (child.DocumentTypeAlias == "doctype2") {
        <article class="doctype2">content here</div>
      }
    
    }
    
  • AlessandroDM 21 posts 122 karma points
    Nov 06, 2017 @ 21:56
    AlessandroDM
    0

    oh great, thank you, so I suppose there is also possibility for switch cases and nested loops, right?

  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Nov 07, 2017 @ 07:10
    Søren Kottal
    2

    Yes, you can do whatever c# you want :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies