Reputation: 5970
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?
Upvotes: 0
Views: 82
Reputation: 1056
I believe segments and variations are something that umbraco will better support in V8. You might be able to get away with using a package called Vorto https://our.umbraco.org/projects/backoffice-extensions/vorto
Vorto is a property editor that you can wrap any other property editor with. It allows you to have different values for different languages. Then, at runtime, you can display the localized version you want. You might be able to use Vorto or a similar approach. Does that seem helpful? If not, could you give us more examples of what you are trying to do?
Upvotes: 0
Reputation: 391
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.
Upvotes: 1