Copied to clipboard

Flag this post as spam?

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


  • Ilias 11 posts 81 karma points
    Feb 23, 2018 @ 22:52
    Ilias
    0

    Different content within the same Document

    I am developing an application with Umbraco and VS 2017. For a certain Document Type, there are a lot of variations in just one small part of its content. What I do not want to do is create a lot of distinct documents for every variation. Is it possible, somehow, to have only one Document and change dynamically only a part of it? If yes, how?

    Then, how would it be possible to call e.g. @Umbraco.Field("body") with some argument (which should define the desired variation) and get the right every time content?

  • Nigel Wilson 945 posts 2077 karma points
    Feb 25, 2018 @ 18:46
    Nigel Wilson
    0

    Hi Ilias

    One possible option is to use nested content.

    I have found it great to provide flexibility for a small aspect of a page.

    The way to set it up is:

    1. Define document types (without template) for the various variations you have.
    2. In developer section create a new data type using the Nested Content and within that add the document types created above. You can restrict the minimum and maximum items.
    3. Then on the page with the variation add the data type created above.
    4. The "fun" bit is then writing the code to "switch" the output based on the variation used on the page. I separate this into separate partials (which may be overkill) but the benefit is that if you have a new variation in the future it becomes a simple task of updating the datatype, and then creating a new partial.

    Happy to provide more detail if needed...

    Cheers, Nigel

  • Ilias 11 posts 81 karma points
    Feb 26, 2018 @ 11:05
    Ilias
    0

    Hi Nigel, thank you for your answer. However I do not have Nested Content in Property editor list. I 've found that's a Umbraco 7.7 feature (my version is 7.6). Moreover, with that solution I have to create about 60 documents (the variations' number) and that's painful. I am thinking of creating one document with the common content and add to it programmatically with C#. What are your thoughts?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 26, 2018 @ 11:22
    Dan Diplo
    0

    Without creating your own (rather complex) property editor there isn't a way to dynamically change a single document type on-the-fly.

    The classic way would be to create a composition with your common properties in and then have each of your doc type variations inherit this common composition.

    But if there are a lot of variations then Nigel's suggestion of using Nested Content for the variations seems the best best. You can install it as a stand-alone package for versions of Umbraco earlier than 7.7.

Please Sign in or register to post replies

Write your reply to:

Draft