Apex - Generate HTML form through string - html

Can I create a HTML form through an apex String ? For instance, I want something like this.
String example = "<p> This is my example </p> <br/>";
But what it returns is " This is my example ", HTML tags does not have its real meaning in it. Is there any other way to achieve this ?
Thank You

What if you replace the html elements with their html entity counterparts:
String example = "<p> This is my example </p&gt <br/&gt";

Related

How to set dynamic JSON String in Thymeleaf

I use Thymeleaf in frontend pages, and for some reason I have to deal with i18n by i18next.js instead of spring framework.
According to the i18next-jquery introduction - using options in translation function, I write like this:
<span data-i18n="myKey" data-i18n-options='{ "WHERE": "TW" }'></span>
And there is my language resource:
{ "myKey" : "User is from {{WHERE}}." }
And html is parsed and showed like this perfectly:
<span data-i18n="myKey" data-i18n-options='{ "WHERE": "TW" }'> User is from TW. </span>
But when I set {{WHERE}} dynamically by Thymeleaf attributes, it just can't be parsed anything.
I tried
th:attrappend="data-i18n-options='{WHERE: '+ ${country} +'}'" also
th:data-i18n-options="'{WHERE: '+ ${country} +'}'",
somehow it just end up like this:
<span data-i18n="myKey" data-i18n-options="{WHERE: TW}">User is from .</span>
So I wonder that is there any idea to parse json string in Thymeleaf attribute ?
Update:
I want to share my solution,and I hope it will save someone's time :)
th:attrappend='data-i18n-options=|{ "WHERE":"${country}"}|'
or
th:data-i18n-options='|{ "WHERE":"${country}"}|'
Please try these two:
th:attrappend='data-i18n-options=|{ "WHERE":"${country}"}|'
or
th:data-i18n-options='|{ "WHERE":"${country}"}|'

Thymeleaf Build-Up a String

I want to create a string variable in thymeleaf by iterating through a loop and concatenating values into this string variable. Then i want to display this string in a <span> element. What i want to achieve can be written in java as follows:
String forDisplay = "";
foreach (MyObject o : myObjectCollection) {
if (o.type == 1) { forDisplay += o.stringValue; }
}
Then in i want to put this in an html element like span. I know how to use:
<span th:each="o : ${objectCollection}" th:if="${o.type == 1}" th:text="${o.stringValue}"></span>
But this creates <span> for each of the elements that satisfy the condition. I just want to build-up my string in a th tag free section and then i just want to display my string in a single <span> element.
Ahmet, take a look at Expression Utility Objects for Strings, from Thymeleaf docs.
You have three methods for joining items:
${#strings.arrayJoin(namesArray,',')} // For Arrays
${#strings.listJoin(namesList,',')} // For Lists
${#strings.setJoin(namesSet,',')} // For Sets
These Utility Objects offers lots of cool methods for Aggregation, Calendars and etc.
Att
Here is how I join numbers into string using ", " as delimiter
<span th:each="instrumentDescriptor, iterStat : ${instrument.instrumentDescriptors}" th:text="!${iterStat.last} ? ${instrumentDescriptor.instrumentVersion} + ', ': ${instrumentDescriptor.instrumentVersion}"></span>

set content of tinymce with a string of html

I have a JSF Renderer that uses responsewriter to generate a jsf page .
In this class I create a String that contains html code , something like this :
String s = "<b>hello</b> <i>world</i>" .
when I create a tinymce editor and set the value of it with responsewriter like this :
responseWriter.writeText(value, null);
it show exactly the same String (showing HTML tag) instead of HTML format of it.
I know it's Wrong to use writeText for writing HTML but I don't know what to use instead.
Try setContent.
responseWriter.setContent(s);
More information here: http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent
finally I solved my problem in this way :
I set the value in a hidden like this :
responseWriter.startElement("input", null);
responseWriter.writeAttribute("type", "hidden", null);
responseWriter.writeAttribute("id", "tinymcevalue" , null);
responseWriter.writeAttribute("name", "required-" + filerRichTextEditor.getSchemaName(), null);
responseWriter.writeAttribute("value", getDocumentFieldValue(filerUIComponent.getSchemaName()), null);
responseWriter.endElement("input");
and then I set it in my JSF :
tinyMCE.activeEditor.setContent(document.getElementById("tinymcevalue").value);

show a smarty variable with html content

I have a smarty variable with html content in it like:
$html="<strong>Content</strong><br/>etc etc"
.
I try to show it html-formatted. When showing it like
{$html}
only plain text appears without formatting. I try like:
{$html|unescape}
but then the tags are shown but not applied. Do you have any suggestions?
Interestingly, none of the answers here work with Smarty 3.1.21 on CS-Cart 4.3.4. So, just to add another thought in that circumstance, use the nofilter on the $html string like so:
{$html nofilter}
You should try this:
{$html|unescape:'html'}
Also check manual:
http://www.smarty.net/docs/en/language.modifier.unescape.tpl
You can try this:
{$html|unescape: "html" nofilter}
Use {$html|unescape: "html" nofilter}
Based on the answer from Sim1-81 and ρяσѕρєя K. I want to explain why the following code works.
The unescape:"html" modifier helps to keep the special characters in place. For example, "€". (Docs).
"nofilter" flag disables $escape_html, which essentially disables the variable being wrapped with htmlspecialchars() (Docs).
Their solution helped as my case was to display a templated block of HTML passed in from a variable.
Some versions of smarty unescape is not available. If this is the case, try using escape:'htmlentitydecode'.
{$html|escape:'htmlentitydecode'}
For those who are using Smarty 2.x, the unescape method is not available, can try this instead;
{$html|html_entity_decode}
you can try :
php function symbol:
function html($str) {
$arr = array(
"<" => "<",
">" => ">",
""" => '"',
"&" => "&",
"\" => chr(92),
"&#39" => chr(39),
"'" => chr(39)
);
return nl2br(strtr($str,$arr));
}
In smarty template call:
{html({$html})}
Or without php function only smarty:
{$html|unescape:'allhtml'}
Notice: if in tpl have use reset css you can try remove it and try again.

splitting a string in as3

i have several strings that look like this:
contactBtn, programBtn, cartBtn.
How can i split these strings so that the "btn" gets discarted, so i keep contact, program, cart.
How would i achieve this?
The String class has a replace method:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html
Check out the Replace() Section of the ActionScript 3.0 Documentation.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#match%28%29
var yourString:String = “contactBtn”
yourString= yourString.split(“Btn”).join(“”);
trace(yourString);
// Output : yourString = "contact"
You would just have to iterate through all of your buttons.
You can also use RegExp :
trace(/.+(?=btn$)/gi.exec("foobtn"));//foo
trace(/.+(?=btn$)/gi.exec("fooBTN"));//foo
trace(/.+(?=btn$)/gi.exec("barbtn"));//bar
trace(/.+(?=btn$)/gi.exec("bar"));//null