Copied to clipboard

Flag this post as spam?

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


  • Thomas Michael Koch 24 posts 96 karma points
    Jul 20, 2014 @ 12:17
    Thomas Michael Koch
    0

    Best practice question - layout templates vs macros

    Hi - I have a "special" page in my umbraco 7 solution, of whom there will only be one instance of.

    I am currently building the special layout directly into the corresponding layout page. However, the page content is driven by the child-nodes to the page, so the layout page will have to iterate over these children to produce the page content.

    Would I be better of putting this iteration logic into a macro?

    I am especially concerned about performance. Would the page be able to benefit from Umbraco caching when the logic for generating the contents is placed directly in the layout file?

    Kind regards

    Thomas

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 20, 2014 @ 12:35
    Jeavon Leopold
    0

    Hi Thomas,

    That is a very good question! I think generally when using MVC templates the best performance comes from using simple logic directly in the Views and Partial Views rather than Macros. This is because the Macro engine itself has a performance overhead compared to native ASP.NET MVC. Macros only really need to be used when you want to allow editors to insert them in the back office (e.g. via RTE). There is a blog post discussing this further here

    But as you have rightly mentioned, what about caching, well Partial Views can be cached, you can find documentation about how to do this here.

    So I would generally only use Views and a cached Partial Views for the best out of the box performance and only use Partial View Macros when I really need to.

    There is a lot more you can do with caching and Umbraco and there a is fabulous video of a session from CodeGarden 2014 that goes through all of the options here.

    Hope that's all helpful for you.

    Jeavon

  • Thomas Michael Koch 24 posts 96 karma points
    Jul 20, 2014 @ 12:38
    Thomas Michael Koch
    0

    Hi Jeavon - many thanks for your swift and thorough reply. :-)

    Thomas

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 20, 2014 @ 12:45
    Jeavon Leopold
    0

    You're very welcome, I hope all the links are useful, the video from CodeGarden is worth a watch :-)

Please Sign in or register to post replies

Write your reply to:

Draft