Passing html in string in include - symfony

I have the code below and I need to pass an html element (anchor) as shown. I have tried using filters like raw and escape but it always prints out the html element as regular text. I also tried setting a new variable that contains the same string text and passed that to testLink and then applied filters to it, but same result. Any ideas how to tackle this problem?
{% include 'example.html.twig' with {'testLink': 'Hurry, Click me NOW'} %}

You cannot handle your problem in the template that is including the example.html.twig template as autoescaping will step in when the passed value is displayed in the included template. Instead, you will have to use the raw filter in example.html.twig (be careful with that solution though as the template is probably used in other places too which might not be safe).

Related

How to allow goog.html.sanitizer.HtmlSanitizer.Builder to permit the "placeholder" attribute

I use goog.html.sanitizer.HtmlSanitizer.Builder to create safe HTML that I then dynamically insert into a dialog. I wanted to have an input field that uses the Html 5 "placeholder" attribute.
I tried
.alsoAllowTagsPrivateDoNotAccessOrElse ([ "placeholder"])
and got an expected nasty compiler error!
I ended up adding the place holder attribute to the closure-library attribute white list javascript code. The call to alsoAllowTagsPrivateDoNotAccessOrElse was removed and all worked well.

Stop TinyMCE 4.1.9 from removing orphaned children tags

I am wanting to use ANY tag inside of TinyMCE without it being removed, but it's not working. My current input is:
<tr><td>[item-thumb]</td><td>[item-count]</td><td>[item-location]</td><td>[item-title]</td><td>[item-desc]</td><td>[low-estimate]</td></tr>
This is used to iterate through items and replace the short-codes with item data, and put that into a table. However, it always strips out the tr and td tags because it is not wrapped in a table tag.
I've tried:
valid_elements: "+*[*]",
valid_children: "+*[*]",
extended_valid_elements: "+*[*]",
verify_html: false,
cleanup: false,
cleanup_on_startup : false,
I know some of these are deprecated, but I'm willing to try anything at this point.
The issue you are running into is that TinyMCE is designed to create valid, well-formed (X)HTML. If you attempt to create table related tags but don't wrap them in a table the HTML cleanup/validation routine will always do its best to cleanup the content to make it valid.
There is no way to disable this validation.
Why don't you just wrap them in a <table>, then just remove <table> and </table> just before saving?
I have done that for something else, but with TinyMCE.
I have the full code in the textarea (where the content of the TinyMCE is), and then used javascript to remove the unwanted code (<table> and </table> in your case) before saving it to a file.
It will work this way:
IF you load the content of the textarea from a database, then just prefix and suffix the content with what you need to make TinyMCE work.
Then get the content from the textarea when you are going to save it, BUT remove the prefix and suffix before writing it to the database/ file.
Doing this should be easy, and gives you endless possibilities.
(You could either do that by javascript, or by PHP (or whatever server side language you use).)

Add dollar sign ($) before CakePHP input

I'm creating a CakePHP 3.0 form, and I have several input fields (Form->input) where users will enter values of United States Currency. I'd like to add a $ symbol to the left of the input box. From my research, it does not appear that CakePHP's Form supports this on its own, so I believe that a CSS solution would be ideal. The corresponding fields in the database are floats.
:before and :after are applied inside a container, which means you can use it for elements with an end tag.
Source
Basically, what that means is you cannot use before on inputs, since it would insert the content into the input.
You can do it with CSS's :before pseudo element, but you have to wrap the input in a element, or place an element before it:
.inputcon:before{
content:'$'
}
Or, you can do it with jQuery:
$("input").wrap("<span class='inputcon'>");
Or with Vanilla JS:
var inputs = document.getElementsByTagName("input");
for(var i =0;i<inputs.length;i++){
var wrapper = document.createElement("span");
wrapper.classList.add("inputcon")
inputs[i].parentNode.insertBefore(wrapper,inputs[i]);
wrapper.appendChild(inputs[i])
}
It sounds like you want to override the input template to include a $ before the input field. The default input template is <input type="{{type}}" name="{{name}}"{{attrs}}>, so it would change to $ <input type="{{type}}" name="{{name}}"{{attrs}}>.
http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses
You could override the entire form (probably not what you want), or just that one input. Most of the examples in the book show you how to override for the entire form, but you can override for just that one input field.
http://api.cakephp.org/3.0/class-Cake.View.Helper.FormHelper.html#_input
Restricting the field itself to only numbers/symbols that are appropriate for a currency is a javascript/html5 issue, separate from cake. If this is what you want, you should also validate server side with cake.
Additionally, somewhat off topic, currency fields should not be stored as floats in the database. They should be stored as some fixed precision type (such as the decimal type in mysql).

Simple HTML Dom get href that begins with

I am using Simple HTML Dom to extract information from a remote source. I would like to get all href links that contain a particular piece of text (not all on a page). I have tried
->find('a[href*="/place"]')
and
->find('a[href="/place"*]')
and
->find('a[href="/place*"]')
but this returns empty results.
The href I am trying to get must begin with the text "/place".
Any suggestions?
Thanks
Match elements that have the specified attribute and it starts with a certain value, use [attribute^=value].
->find('a[href^="/place"]')
Ref: http://simplehtmldom.sourceforge.net/manual.htm#frag_find_attr
I do not now this app, however did you try using the asterisk like so ?
>find('a[href="/place*"]')

How to deal with special characters in ASP.NET's HyperLink.NavigateUrl?

I am currently having troubles figuring out how to handle a filepath to be (dynamicly) passed out to a HyperLink control's NavigateUrl property.
Let's say that I'm trying to refer to a file named jäynä.txt at the root of C:.
Passing "file:///C:/jäynä.txt" result to a link to file:///C:/jäynä.txt, as does HttpUtility.UrlPathEncode("file:///C:/jäynä.txt").
Replacing the ä**s with **%E4, which gives the string "file:///C:/j%E4yn%E4.txt", does give a working link to file:///C:/jäynä.txt, but I have not been able to find a way to make the replacement without defining it myself. With Replace("ä", "%E4"), for example.
Is there a way to automaticly handle the filepath string so that the HyperLink would display it correctly, without manualy listing what characters to replace in the string?
Additional Note:
There may be a way to work around this by spesifying the character encoding in which the page is rendered, because debugging shows that the HyperLink at least saves the string "file:///C:/jäynä.txt" unchanged, but somehow mangles it around the time of rendering.
However, this seems only be the case in rendering of the NavigateUrl because other components as well as HyperLink's Text-property are all quite capable of rendering the character ä unchanged.
The NavigateUrl property of a Hyperlink will encode unicode chars in the url.
Instead you can set the href attribute property of the Hyperlink like this:
hyperlink1.Attribute("href") = "file:///C:/jäynä.txt"
This is due to how the browser starts to interpret the path, typically individuals will avoid using characters such as that in the urls of pages.
In your case, I believe you have struck upon the best case scenario, as I am not aware of any way to change the behavior of HttpUtility and/or the NavigateUrl property. At least not without creating a custom control for it.
Don't use HyperLink control. Instead use HtmlAnchor control. It will solve your problem. I don't know why Microsoft designed like this.
Thank you!
The post using the 'attributes' solved my problem. In my case it was
HyperLink6.Attributes["href"] = "http://høgstedt.danquah.dk/";
The problem of using special danish characters in a url seem to have been troubling a lot of programmers - a search provides several very complicated approaches. This one is SIMPLE and it SIMPLY WORKS.
So once again, thank you

Resources