Copied to clipboard

Flag this post as spam?

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


  • Roland Egedi 10 posts 110 karma points
    Dec 11, 2019 @ 12:22
    Roland Egedi
    0

    Macros in v8 (should they be used?)

    I am new at Umbraco and have only used v8.

    I watched a video learning about Umbraco 8, but now I can't find that video... But in the video I think the dev said that going forward we shouldn't use Macros in Umbraco since this would be phased out (or something like this).

    But I can't really find any info on this, and I can't find that video again. 🤯

    So is my memory correct? Or did I inhale heavy CPU-fumes while watching the video..?

    I did find this discussion, but it is from 2016: https://issues.umbraco.org/issue/U4-8964

    Is it "best practice" to use Macros in v8? Also going forward, regarding updates and so on?

    Thanks!

  • Steve Megson 151 posts 1024 karma points MVP c-trib
    Dec 11, 2019 @ 15:36
    Steve Megson
    100

    I wouldn't say that we shouldn't use macros at all, but they are needed much less often than in previous versions. Many things that needed a macro before can be done with a partial view, and if a partial view will do the job then you should probably use one.

    The main reason to use a macro will be if you want to embed it within a grid or rich text editor. I think I'd only use a macro directly in a template if I want to cache the results. You can also use Html.CachedPartial to get similar effects, but sometimes I find it useful to be able to see the cache settings in the back office rather than having them set in the template.

  • Javed 7 posts 88 karma points
    Dec 11, 2019 @ 17:20
    Javed
    0

    I also would like to know if Macro usage is not a good practice and whether it will be deprecated in future releases.

    In my current (first) Umbraco project, I am heavily using Macros for:

    1. Componentize page
    2. Reuse content across the site with Macro Parameters
    3. Render different UI for same content
    4. Nice authoring experience like WYSIWYG

    Let me know if there is another better approach to achieve these goals.

    Thanks.

  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Dec 11, 2019 @ 19:29
    Heather Floyd
    1

    Roland & Javed, Welcome to Umbraco!

    Javed: It's hard to know whether using Macros is the "best" approach without understanding you specific use-case a bit more. Some of the things you list might be better served with another approach, such as Nested Content, the Grid control, or an RTE.

    For my own projects, I have used Macros when I wanted to allow the Content Editor to drop some "dynamic" content into an RTE or Grid.

    Specifically for things like selecting a list of "features" (articles, links, etc.) which I want to control the actual HTML rendering for, or something like "Latest News" - which will handle the selection logic, but I want to allow them to set some options, like Quantity to return, etc.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 11, 2019 @ 19:41
    Nicholas Westby
    1

    I don't recommend rich text macros (which are different from grid macros). Some info here: https://24days.in/umbraco-cms/2015/umbraco-zeitgeist/#macros

    I think I read recently that macros (at least in Umbraco 7) cause a database query when a page is rendered. If true, that's another reason to avoid them (because that could slow down the page render times).

    If you are using widgets (e.g., Archetype, Nested Content, Grid, etc.), there isn't really a need for them, aside from perhaps some edge cases.

  • Javed 7 posts 88 karma points
    Dec 12, 2019 @ 03:02
    Javed
    0

    Thanks Heather & Nicholas.

    I was planning to use Macro with Grid, but I will look into Nested Content to see if it fits in our requirements.

    Thanks again for the tips & suggestions.

Please Sign in or register to post replies

Write your reply to:

Draft