Copied to clipboard

Flag this post as spam?

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


  • Nadine Fisch 159 posts 429 karma points
    Jul 25, 2018 @ 06:31
    Nadine Fisch
    0

    Reuseable Content - Best practice

    Hey people,

    I want to create a simple banner ( some text and a button with a special layout) and I want to make it reusable for detail pages, but only with some specific content.

    In the last time, I often used macro partials to insert some code fragments to my content pages. So I can easily reuse it. But in this case it seems to be too much, because the banner doesn't have much logic.

    But on the other way, I don't want to make a property to show this banner on some pages, it also seems as I would integrate too much unneccessary properties for pages where I don't need this item.

    So, can you please tell me how you would solve this task in a "clean and friendly" Umbraco manner??

    :) Thank you for your advice,

    Nadine

  • Ganesh Kumar 8 posts 79 karma points
    Jul 25, 2018 @ 11:48
  • Harry Spyrou 212 posts 604 karma points
    Jul 25, 2018 @ 15:05
    Harry Spyrou
    0

    Hello Nadine,

    Are you familiar with the repository pattern in Umbraco?

  • Nigel Wilson 944 posts 2076 karma points
    Jul 25, 2018 @ 19:28
    Nigel Wilson
    0

    Hi Nadine

    So in saying you only want it for some specific content are you referring to specific document type(s) ?

    My response is assuming the answer to the above is "Yes"

    So:

    1. Create a composition document type for your banner
    2. Include that composition on all document types you want the banner to appear.
    3. Create the associated partial for the banner
    4. Add the partial to your template

    The partial from step 3 should have something along the following lines:

    if (Model.Content.HasProperty("bannerImage") && Model.Content.HasValue("bannerImage")) {
        -- your banner html output code goes here
    }
    

    Hope this helps.

    Cheers

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft