Smarty 3: how can I output a variable and not have html entities converted? - smarty

In a specific template, I'd like to be able to output a variable, and not have the quotes, such as ' turned into html entity codes (')
How can I do that without affecting how the rest of the system is working?
I've tried:
{$var|escape:'html'}
{$var|escape:'htmlall'}
{$var|unescape}

To make a variable exempt from default modifiers, add the 'nofilter' attribute to the output tag such as {$var nofilter}

Related

How to stop go html/template from escaping a path (tried .HTML .JS etc.)

I am using the html/template functionality to assemble a page and on of the variables I'm supplying to the template is URI in the form "/some/path/etc" which is used as a parameter to a JS function called in a onClick="..".
No matter what, the string used in this configuration will be escaped with backslashes : "\/some\/path\/etc"
As you can see in the playground example below, I tried all the .HTML(), .JS() etc. functions but nothing seems to stop the escaping.
See Go Playground example here: https://play.golang.org/p/2gdghTpQHKP
How can I get this URI "as is" into the template result?
Thanks to mkopriva for his comment.
As far as I could see there is no way (as mkopriva mentioned) to handling a HRML attribute value fragment in a Go HTML template.
So the options are:
Leave it as is (it seems that at least in my use case the URI even works in the further processing with the escaped forward slashes)
first concatenate the complete attribute, so that the "HTML Attribute" way will accept it
Write a construction function that takes parts and assembles the final attribute value inside the template execution
Hardcode the value in some form

In YAML, is there any way to use variables inside a literal block scalar?

I'd like to use a variable inside a YAML literal block scalar.
Here's what I'd like to do:
markup: |
<title>
{{ title }}
</title>
Can that be done somehow?
I appreciate that this example would be trivial to execute without using a literal block scalar, but my actual use case inside a Foundation 6 stack would contain more markup and more variables than what I'm showing here.
There is no such thing as a variable inside a literal block scalar.
First of all there are no variables in YAML (the word variable, occurs only once in the YAML specification, in an example document, nr. 2.28).
And second, this is called literal for a reason. No interpretation is done of any of the characters.
Of course it is possible that some program that loads your document does something with the text between curly braces ({}). E.g interprets it as a jinja2 template. But without knowing what such a program does or expects, it is equally valid to expect something like that for the information between angle brackets (<>).
Therefore within YAML there is no way to use variables, neither inside of literal block-style scalars, nor outside them.
As for the templating: I have worked with program that generated YAML from a template and applied templates on the loaded string scalars (by recursively walking the tree). Your example could be either.

How to output ${expression} in FreeMarker that contains HTML AS HTML

In my data model myVar contains <b>hello</b> and when I bring it like this ${myVar} the output I get is literally <b>hello</b> rather than hello.
Any idea how to correct this?
Certainly you have HTML escaping on, so try <#noescape>${myvar}</#noescape>.
Update: Since 2.3.24 a new kind of auto-escaping was introduced, which doesn't use #escape, and hence nor #noescape. When that's used, write ${myvar?no_esc} to avoid escaping. Or, you can put the value into the data-model already as a TemplateHTMLOutputModel (created with HTMLOutputFormat.fromMarkup(myString)), and then FreeMarker will know without ?no_esc that it need not be escaped.

How to create variables in a template file in ruby?

I want to have a text template file that would contain variables.
the file is read
variables replaced with its values
the file is saved
I tried to have a file with #{my_variable} but actually the character # is escaped so #{my_variable} is not replaced with the value of the variable because it's text.
tried to escape # in the text file \# but it didn't work
Is there any way that I don't have to do search and replace in this scenario?
As clyfe mentioned, you should definitely be using ERB's for this:
http://www.rrn.dk/rubys-erb-templating-system/
This will let you use variables, loops, methods, etc. and is far more robust.

Freemarker escaping freemarker

I'm using freemarker to generate a freemarker template. But I need some way to escape freemarker tags.
How would I escape a <#list> tag or a ${expression} ?
You could also use: ${"$"}{expression} if you find the {} nesting confusing.
I'm using the alternative syntax feature. I start the template with [#ftl] and use this syntax.
For the expressions I use the string literal feature: ${r"${expression}"}
You can configure FreeMarker to use [=exp] instead of ${exp} (since 2.3.28), and [#...]/[#...] instead of <#...>|<#...> by setting both the interpolation_syntax and the tag_syntax configuration setting to square_bracket (in the Java API: Configuration cfg; ... cfg.setInterpolationSyntax(Configuration.SQUARE_BRACKET_INTERPOLATION_SYNTAX) and cfg.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX)). Then the syntax doesn't clash with the default syntax.
There's one tricky case; if the template starts with <#ftl>, then it will switch the tag syntax back to angle_bracket. To counter that, just add a [#ftl] line before it.
See also: https://freemarker.apache.org/docs/dgui_misc_alternativesyntax.html
In the case when you want to use non-raw strings so that you can escape double quotes, apostrophes, etc, you can do the following:
Imagine that you want to use the string ${Hello}-"My friend's friend" inside of a string. You cannot do that with raw strings. What I have used that works is:
${"\x0024{Hello}-\"My friend's friend\""}
I have not escaped the apostrophe since I used double quotes.

Resources