How to use Razor like asp:Literal? - tags

I have a simple Model:
public class MyModel
{
public string Text{get;set;}
}
I have a View, which renders Text property of MyModel:
<p>#Model.Text</p>
How can I render html tags from Text like tags? For example, I have Text "<b>Text</b>". I want to get bold text inside tag p as result:
Text
But Razor renders text as is:
<b>Text</b>

I think you need to use it like:
<p>#Html.Raw(Model.Text)</p>
You can find more info here on Phil Haack's blog.
anurse points out in the comments that you could, alternatively, set the type of the Text member of your View Model type as IHtmlString and just use #Model.Text to output it. ASP.NET MVC is clever enough to realize that the output should not be escaped.

Related

Can not output image title and description for TYPO3 extension DCE images

I created in TYPO3 extension DCE an image field that allows to input an image with caption and title field in the backend. But I couldn't access the value of these fields to input in the alt-tag in source. No values are shown by f:debug, how can I access these values and output?
The fastest solution would be having a look into the Class Reference of TYPO3\CMS\Core\Resource\FileReference. There are many getters for the properties. They access (and are allowed to access) the mergedProperties-array. In your special case getDescription() is, what you are looking for.
So for getting description a simple {field.imageDesktop.{i}.description} should work (if field.imageDesktop.{i} is a FileReference).

Cannot programmatically add content to simple HTML DIV Element in XML view

I have a simple XML view (fragment) like this:
<html:div id="holder"></html:div>
I want to add content programmatically like this:
var holder = this.byId("holder");
var label = new sap.m.Label({
text: "Label"
});
holder.addContent(label);
Effect is nothing, no error, no added content.
Why does it not work?
This is because content is not an aggregation (an easy mistake to make, since content usually is an aggregation).
sap.ui.core.HTML's content metadata object is a property of type string. From the jsdoc:
HTML content to be displayed, defined as a string.
You will need to use a different container for your label, such as sap.ui.layout.VerticalLayout, or you could just use raw HTML to stick in your holder object, rather than that sap.m.Label type.
Here is a jsbin that takes the XML view part of this question out of the equation.
Note: See #hirse's comment below for an important distinction when using html:div in XML views
The HTML element and the UI5 Controls are not directly compatible. UI5 Controls are JavaScript objects that have a render function. The render function creates a html fragment on demand. That html fragment ist then inserted into the page.
I have never tried it, but a solution could be to use the placeAt() method of your label:
label.placeAt("holder");
If you are using an XML View, the holder id will be prefixed. Then you should use something like this:
label.placeAt(this.getView().createId("holder"));
You can get DOM element of UI5 control by using getDomRef of sap.ui.core.Element class.
Then add your content to this DOM element by using placeAt()
Here is working example.

Play Framework Html class and Form Rendering without Input

I have 2 questions. Version 2.4.x of the Play! Framework.
Whenever I render a layout using layoutName.render(inputargs...); it returns an "Html" object. I have not found a reference to this class in any of the docs. Where do I find this class? This doesn't seem to yield anything. (Edit2: Found in play.twirl.api.Html)
I am rendering a search bar on every page which is created using an input form. The problem is that the main layout needs my model class for the form as an argument: mainLayout.render("title", something_else, new Form<Search>()); Is there any way of writing it as mainLayout.render("title", something_else); whilst still retaining the form?
Edit3: Apparently the form is not needed at all; so long the name of the input is the same as the model's name any form will work:
#helper.form(action = routes.SearchPage.search()) {
<input type="text" name="term">
}
will work for a search term, but only as long as "term" is a public variable of the class in which we are going to store the post data.
Edit:
Currently using a method that inserts the empty form. The problem is that the Html class is not found. I have no idea where it is located.
public static Html renderMainLayout(String title, java.util.ArrayList<String> content) {
play.data.Form<Search> userForm = play.data.Form.form(Search.class);
return layout.render(title, content, userForm);
}

What does CQ5's Placeholder.getDefaultPlaceholder exactly do?

The API docs are not much descriptive:
Get default placeholder for any component incl. title as text information
Here's the method signature:
public static String getDefaultPlaceholder(ServletRequest slingRequest,
Component component,
String defaultPlaceholder)
What's a Placeholder? What is/should be returned by getDefaultPlaceholder?
What's the purpose of defaultPlaceholder? What should I pass as defaultPlaceholder? What would happen if I pass null?
When a component does not have any content defined you need to put a placeholder to occupy its place (for the editor to know there's a component there).
The getDefaultComponent returns a HTML snippet that works as the placeholder. It consists of an empty div with attributes class and data-emptytext with the title of the component as its value.
<div class="" data-emptyText="component.getTitle()"></div>
You can also pass an additional parameter with a list of strings and they will be added in the class attribute of the div.
getDefaultPlaceholder(ServletRequest slingRequest,
Component component,
String defaultPlaceholder,
String... addClasses)

How to you change the markup value for a text element using DynamicJasper?

I am using DynamicJasper to generate reports from some tables at run time. I have some fields that the data has been styled using basic html tags as the data was created. Very basic tags like bold and italic, and jasper reports can handle them by setting the markup attribute of the textElement to html. The problem is a can not find a way to change it using DynamicJasper.
I have tried using addFieldProperty("markup", "html") found in ColumnBuilder, but that adds markup as a property to the field markup (probably obvious that it should do that based on the name) instead of the text elemennt.
How to you change the markup value for a text element using DynamicJasper?
The DynamicJasper API does not contain methods to set markup.
But you can use JasperReports API for this needs.
For example, the JRBasePrintText class and JRCommonText interface have method for setting markup:
public void setMarkup(java.lang.String markup)
The JRCommonText interface has constant fields:
public static final String MARKUP_NONE = "none";
public static final String MARKUP_STYLED_TEXT = "styled";
public static final String MARKUP_HTML = "html";
public static final String MARKUP_RTF = "rtf";
You can modify DynamicJasper classes for your needs like in this post, for example.