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?
It's not quite clear what you're trying to achieve but if you can put a special marker field (say {{UNIQUE_BIT_HERE}} ) in the body content (or there is a particular html tag/attribute you can find and replace) then it's easy - just use standard c# string manipulation.
I'm assuming your field "body" is a rich text field, if so it needs converting from the HtmlString type to a standard string and then back again.
@{
var uniqueData = "Whatever";
var bodyString = Umbraco.Field("body").ToString();
var bodyReplaced = new HtmlString(bodyString.Replace("{{UNIQUE_BIT_HERE}}", uniqueData));
}
<div>
@bodyReplaced
</div>
As an aside I'd suggest you move away from Umbraco.Field and use the strongly typed Model.Content or, better still, the models builder Umbraco stuff but this will work.