Copied to clipboard

Flag this post as spam?

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


  • Stefan 6 posts 76 karma points
    Aug 02, 2021 @ 11:36
    Stefan
    0

    Reusable / shared blocks, built-in functionality in Umbraco? (v8.6.4)

    Is there built-in functionality for reusable / shared blocks (ie: using the same block on multiple pages) in Umbraco version 8.6.4?

    Or is this only achievable through plugins / custom code?

    Thanks in advance!

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 02, 2021 @ 12:02
    Søren Gregersen
    0

    Hi Stefan

    If you create content without a template, the content will not be able to be routed (no url), thus creating a "shared block". https://our.umbraco.com/documentation/tutorials/creating-basic-site/document-types/

    To render the "shared block", you can just render it using a partial view https://our.umbraco.com/Documentation/Reference/Templating/Mvc/partial-views

    HTH :)

  • Stefan 6 posts 76 karma points
    Aug 02, 2021 @ 12:09
    Stefan
    0

    Not quite what I was looking for.. The block templates are already created.

    What I'd like to achieve is the possibility to create a block with content which can then be referenced on multiple pages.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 02, 2021 @ 12:13
    Søren Gregersen
    0

    create a block with content which can then be referenced on multiple pages

    In umbraco you have to put the content somewhere in the content tree. Creating node without a template, is a way for the content to not get an url.

    A similar solution has been discussed here https://our.umbraco.com/forum/using-umbraco-and-getting-started/92091-reusable-content and here https://our.umbraco.com/forum/using-umbraco-and-getting-started/104665-how-to-do-reusable-content-global-content-for-content-editors

    I would just suggest not using a macro, and use a content picker and a partial view instead.

    You would need to share the templates (or copy the content) every place you display the shared content.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Aug 02, 2021 @ 12:25
    Søren Gregersen
    0

    If you want to reuse a part of a page, say a footer, that you create on the homepage of your site, you could reference the "homepae" from any page you have, and then render the "footer" of the "homepage".

    Something like this :

    @{
        var homepage = Model.Content.AncestorOfSelf("homepage");
        if(homepage != null)
        {
          // partial view, that renders the footer...
          Html.RenderPartial("Footer", homepage);
        }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies