Copied to clipboard

Flag this post as spam?

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


  • Topic author was deleted

    Nov 06, 2017 @ 19:22

    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 712 posts 4570 karma points MVP 6x 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>
      }
    
    }
    
  • Comment author was deleted

    Nov 06, 2017 @ 21:56

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

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

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

Please Sign in or register to post replies

Write your reply to:

Draft