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 />")"
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.
Related
I am using ASP.NET MVC, when I want to use the tag in #Html.Raw, this tag does not appear in the desired <div>.
As shown here:
<div class="mt-4 current-cursor">
#Html.Raw("<strong>OKK</strong> <p><ul><li style='font-size:18px;'>1.Test1</li><li>2.Test2</li></p>")
</div>
The result that it displays for me is as below, that is, it does not recognize the <strong> tag at all.
Html.Raw does not interpret anything at all. It just spews the given string unencoded into the output docuument.
So if it doesn't look right in your case, possible you have some CSS in that page that causes it to look as it does. You could use F12 (Developer Tools, depending on your browser) to inspect the "OKK" for details.
BTW, the other tags in your example also look wrong (which could also be an issue given existing CSS in the page).
In my case, for example, using some (other) arbitrary styles, your code looks like this:
I have created a Blazor server side application. And then add the custom component inside the MarkupString. MarkupString only converts the declared string as a HTML tag. But it will not convert the custom component as a HTML elements. Is this supported in Blazor platform.
Counter declares the counter component (custom component):
<div style="height:100%; width:100%;">
#((MarkupString)#Markup)
</div>
#code {
string Markup = "<Counter></Counter>";
}
Counter.razor page contains the following code.
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
Expected output:
I am expecting to execute the counter component and render the output elements in DOM.
Can MarkupString property convert a string of custom component into HTML elements in DOM
No, it can't.
MarkupString allows you to render raw HTML. It parses MarkupString content as HTML or SVG and then insert it into the DOM. However, it won't render your Counter component. Instead it converts the tag to lowercase, and treat it as an HTML tag. This is the result:
<div style="height:100%; width:100%;">
<counter></counter>
</div>
Is this supported in Blazor platform.
As you can see, it is not. However, that might be possible in the future, perhaps by the Blazor community. I'm not sure about this, but I think that Steve Sanderson had something related to this...
Hope this helps...
I've been working on a small school project and decided to use .net core (MVC) for the first time. I have a small button I can click which executes the "ipconfig" command in the background and displays the output in a text area. At first my team partner used only a
public string Result;
in ViewModel for the view. In the view it's displayed via
<textarea asp-for="Result"></textarea>
So I decided to make it into a property with default get and set:
public string Result { get; set; }
But when I do that, the output doesn't show up in the textarea if I keep the same approach in the view as my team member did when he used a field instead of a property. Instead I have to do it like this to get it to show up in the textarea:
<textarea>#Model.Result</textarea>
Now I'm asking myself why this happens. Can't I display Properties with asp-for? And what would be better to use, a field or a property as Result?
Many thanks in advance!
In my case this behavior was happening because I did not have a separate closing tag on my textarea. I know your example above has it when using the asp-for method, but in case that was a copy/paste error, you may want to look at that again.
<textarea asp-for="Message" type="text" class="form-control" rows="5" id="MessageInputField" autofocus></textarea>
As opposed to:
<textarea asp-for="Message" type="text" class="form-control" rows="5" id="MessageInputField" autofocus />
This is incredibly annoying 'gotcha' like behavior in my opinion. And maybe if someone wants to tell me why it isn't, then please enlighten me, I'm always willing to learn.
You should actually be using properties, and if <textarea>#Model.Result</textarea> works, <textarea asp-for="Result"></textarea> should as well. The only reason it wouldn't is if the ModelState has a different value for Result (as the latter form actually uses ModelState, whereas the former is obviously using Model directly).
ModelState is composed of values from Request, ViewData/ViewBag, and finally Model, so for example, if you were to do something like ViewBag.Result = String.Empty, that would actually override the value from Model in ModelState.
There's no enough code here to truly diagnose the exact issue, but I would look for other places you might be using "result" (case-insensitive). If you're accepting that as a request param or setting a ViewBag member, etc. that's your problem.
I find this is a bit weird in .Net Core 6, when I want two-way binding - ie displaying the result
With asp-for I have to self close the tag AND add the additional textarea close tag to get the result displayed.
<textarea asp-for="Result" />#Model.Result</textarea>
This works but is not syntactically correct.
Without the self-close tag, the result was not being display
<textarea asp-for="Result">#Model.Result</textarea> #*Does not display the value*#
For display only, this is more correct
<textarea>#Model.Result</textarea>
So I'm developing a Model View Controller (MVC) project. Due to the size and complexity, I'm trying to ensure organization. I've managed to stumble on a unique quandary, one that has left me quite stumped. My issue is drawn from a Jquery Rotator that I'm integrating into my site.
My Solution Explorer:
Content : This particular folder contains three direct sub-folders Images, Scripts, and Stylesheets.
Those three sub-folders contain more specific and honed in details, an example would be the Scripts contains another folder called Rotator for this jQuery implementation.
So the dilemma occurs inside the View.
An example within this View:
<div class = "banner-style">
<div id = "Infinite-Banner">
<div class = "banner-container">
<div class = "slides">
<img src = "~/Content/Images/Banner/Slides/One.jpg">
<img src = "~/Content/Images/Banner/Slides/Two.jpg">
</div>
</div>
</div>
</div>
So within this structure it doesn't appear to load the Images. Though it is properly mapped to the directory. But if you use the same structure above but change the img portion to:
<div class = "slide-one" />
<div class = "slide-two" />
Then in a the correlating Stylesheet, simply define a background: url(~/Content/Images/Banner/Slides/One.jpg); for the slide-one Element it magically appears.
So this makes me believe that it is due to nesting. But doesn't quite make sense, as this will force me to build an inner element between the div slides so that I can generate the proper affects.
The other idea would be to create a model that maps all the relational image data; but that seems like an awful lot of work.
Is this a limitation or an issue specific to my machine? What would be the best work around to such an issue? Is this indeed due to the structure I've taken to my folders?
Try using the Url.Content method:
<img src="#Url.Content("~/content/images/banner/slides/one.jpg")" />
You didn't post what the actual URL is being built as, but, I would guess that the path is wrong because whatever controller you're hitting is being used in the relative path.
I am beginning to study the very nice CMS Orchard and, after reading the basic documentation, I've stumbled in a little hurdle.
I've created a new DataType, 'SpecialOffer', which has some dataparts and some text datafields:
ProductName
PhotoURL
Price
Description
I've made a list, made a widget, customized the position.info file and the Views\Fields\Common.Text.cshtml file to change the position and the way the fields are rendered (a img for the photo, prepending € to the price and so on) but this doesn't give me the right amount of customization over the generated html.
I've installed the developer shape tracing module and created an alternate Content-SpecialOffer.cshtml file.
This gives me the opportunity to easily customize the HTML around the content, but I have no idea how to get to the single DataItem fields to display them the way I want.
I mean that the whole SpecialOffer object is displayed through
#Display(Model.Content )
and, exploring the model, I've not found a way to write something as, say (pseudocode)
<div>
the
<span class="name"> #Model.Contentitem.Fields["ProductName"]</span>
camera costs
#Model.Contentitem.Fields["Price"]
euros
</div>
I've read this post on SO
Custom View For RecentBlogPosts in Orchard
but it does not solves my problem, since it uses the standard properties of blogpost.
another little question: other than in the Documentation page of project orchard and b. LeRoy's http://weblogs.asp.net/bleroy/ where can I study Orchard?
Thanks!
Edit
I've found a way to do it:
#{
dynamic offer =Model.ContentItem.SpecialOffer;
}
<div>
the
<span class="name"> #offer.ProductName.Value</span>
camera costs
#offer.Price.Value
euros
</div>
is this the right way?
Yes, that's fine.
After the docs and the RSS feed on the home page of orchardproject.net, a major source of information (better than the previous 2) is the source code for the app and modules.