Copied to clipboard

Flag this post as spam?

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


  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 08, 2012 @ 15:31
    Rune Grønkjær
    0

    Boxes/Widgets with razor

    Hi Guys,

    I'm working on a new setup for looping out boxes (or widgets as other would say) on our websites. I'm thinking of using the Widget Grid by Matt and needs ideas to how to do it best. I'm working width two ideas, none of them are optimal i think, so I hope you have some input.

    Basically the Widget Grid provides a list of node ID's that I need to render into some markup.

    Idea 1
    Make one large razor file with one method per document type that I need to handle. I'll then do a switch case on each node and create the markup for that node.
    The problem is that potentially this file could become quite large if theres a lot of different types of boxes.

    Idea 2
    Use the RenderTemplate method to render the box as a page this a specific template. This is nice because I can then have separate razor files. The problems are that the RenderTemplate method makes currentPage to the box instead of the actual currentPage. Furthermore I need a template for all box nodes, which I don't in idea 1

    How about it. Any other great ideas. I'm not very fond of any of my ideas, but idea 1 will be the one I choose if you guys can't come up with something brilliant.

    Thanks

    /Rune

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 09, 2012 @ 08:20
    Chriztian Steinmeier
    2

    Hi Rune,

    I'd definitely go with number 1 (not that I'd actually go Razor, u know :-) - the filesize "problem" is just a maintainability problem, right? There's no real impact of a large file when compiled (?)

    I do the equivalent in XSLT with separate templates for each Widget type - as soon as the file grows large, I split it into separate files, using an include statement to assemble them (the XSLT is compiled once, so no real penalty here either).

    And you know you definitely want currentPage to be the actual page, not the Widget.

    Anyway, what do I know about Razor ... :-) There's probably an even better option somewhere...

    /Chriztian 

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 09, 2012 @ 08:24
    Rune Grønkjær
    0

    Thanks for the input Chiztian. That's also what I do with xslt today.

    Yes the file size is only a problem because of the maintainability. It's a big "only" in my world though. It will be ugly and not very good practise. So I was hoping some of the Razor fanboys had a better idea. I'm not hooked on razor yet. It's OK but seems to be hard to work with.

    /Rune

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 09, 2012 @ 08:49
    Sebastiaan Janssen
    2

    You can always do some seperation by using RenderPartial so you don't have ALL the code in one file (better for source control as well):
    http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/@renderpage-with-args

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 09, 2012 @ 09:19
    Rune Grønkjær
    0

    Sweet. If that works you are my hero. I have trawled google for that single piece of information. Will check it out right away.

    Thanks Sebastiaan.

    /Rune

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 09, 2012 @ 09:49
    Rune Grønkjær
    1

    And it works. Once again you save my day Sebastiaan. Thanks a bunch. :)

    HFYR

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft