0
votes

I am styling up a website that is using Orchard and I have noticed their is a custom content type which has a message, here is a standard message in HTML

<p>Some text</p>
<p>Some more text</p>

This is fine however thanks to the Orchard.Core.Common.Views.Fields.Common.Text.cshtml it is inserting a <br /> after each </p>

Here is their view which is rendering the message

@using Orchard.Utility.Extensions;
@{
    string name = Model.ContentField.DisplayName;
}

@if (HasText(name) && HasText(Model.Value)) {
<p class="text-field"><span class="name">@name:</span> <span class="value">@(new MvcHtmlString(Html.Encode((HtmlString) Model.Value).ReplaceNewLinesWith("<br />")))</span></p>
}

How can I override this? I have tried to copy and paste the view into my Themes/View folder but it doesn't seem to override it. I just want to remove the ".ReplaceNewLinesWith("<br />")"

1

1 Answers

0
votes

I haven't tried this with Orchard 1.6, however this works fine with the latest version (1.8). The obvious things to check are that your theme is active and that you given your view the correct name. If you want a global override then the View should be in the root of your themes View folder, with the name 'Fields.Common.Text.cshtml'.

If you don't want to change the behaviour for all text fields, then you may want to turn on shape tracing and find an Alternate for the view that is tied to either the field name of the content type that it's contained in (for example 'Fields.Common.Text-SomeTextField.cshtml'. This would reduce the impact of any change you make.

That said, are you sure you're doing the right thing though? If your content contains <p> tags then at least in the latest version, the tags will be stripped, which makes sense since otherwise you'd end up with nested <p> tags:

<p class="text-field"><span class="name">SomeTextField:</span> <span class="value">
    <p>Some text</p>
    <p>Some more text</p></span>
</p>

Also, as a warning, whilst it is certainly possible to override this view in the latest version of Orchard, the view has actually changed so that the new line processing is no longer in the view. It has been moved out into a Filter Orchard.Core.Common.Services.TextFieldFilter. So if the site is updated in the future you may find that you need to revisit the area.