smarty escape single quote in if else condition - smarty

need some help from smarty expert.
I am new in smarty template engine.
I would like to escape a single quote in a string, how can I do that
inside my .tpl
I got a if else condition
$current_category.category eq 'King's Tea'
the problem is the 'King's Tea' , that is my category name,
I tried 'King\'s Tea' , Smarty can't convert it
I tried {litereal}'King's Tea'{/litereal}, this one doesn't work in if else condition.
is there any way I can escape the single quote?
I tried to search in smarty API side. the escape page, just tell us how to escape from the variable.

$current_category.category eq "King's Tea"

Related

UiPath - how to use variables in switch/case

I'm just curious about switch/case in UiPath.
Everywhere else in UiPath, strings must have double quotes or stored in variables, however in switch/case, it seems different.
Every "case" is interpreted as string, regardles of the quotes.
How to use variables in there when they're interpreted as string?
You cant use variable in switch case in UiPath. However you can use following expression in Expression property helps switch dynamically.
Array.IndexOf({var1,var2,var3},item.ToString)
Something like below screenshot
Hope this helps

Escape single quote in Xtend template expression

I have a very simple question, but could not figure it out by Google search, please help.
I want to produce this string '\u0000' (note the simple quote marks surrounding it!) using the following simple Xtend method containing a template expression:
def String makeDefaultChar()
{
''''\u0000''''
}
However, this is not accepted as proper syntax (probably because of the four ''''. Is there an escape character for this use case or what is the right syntax?
Thank you in advance!
P.S.
Of course I could use plain Java string like this "'\\u0000'" to achieve the same, but I want to use an Xtend template expression.
My Xtend version is: 2.9.1.v201512180746
There is no "escaping" in template expressions, so you have to use the workaround you mentioned:
'''«"'\\u0000'"»'''
or
'''«"'"»\u0000«"'"»'''
Related discussion: https://groups.google.com/forum/#!topic/xtend-lang/bVZ0nKmQGAI
Single quotes are allowed within Xtend templates as long as they do not occur at the beginning or the end of the template. So a simple workaround is to add an empty expression before/after the single quote:
'''«»'\u0000'«»'''

Blade engine: print triple curly braces

I know how to print double curly braces in Laravel: #{{ }}.
But how can I print triple curly braces? My first thought of adding an # before does not work, Laravel still tries to interpret it.
Is there an easy way without encoding the braces to HTML entities?
Update
Very recently, a pull request was merged that fixes this problem!!
As of Laravel 5.1.7 it is possible to use the # sign as expected:
#{{{ ... }}}
Original Answer
The least ugly workaround I found up until now is to escape the first two brackets as normal and adding an invisible between them and the third bracket:
#{{‌{test}}}
I'll investigate further and update this answer if I find something better...
This is the easiest way. Use HTML entities to escape curly braces. Tested in Laravel 5.
See here for the list of HTML entities. HTML Entities
Code
{{{text}}}
Output
{{{text}}}
Use this if you just want to print them:
{{ '{{{' }}
One more way is as following
{#{{Text}}}
I ran into the same issue trying to render some raw HTML using Vue.js in laravel 4.2. For me the easiest solution was to just to use a simple php echo statement in the blade template:
<?php echo '{{{ text }}}'; ?>
Did the trick for me.

.tpl file and %%. Is this smarty?

I have a .tpl file which has %% variables in it.
Example:
%%GLOBAL_Error%%
Is this a smarty template engine file?
I want to check if this variable is not empty, but I can't do this with regular smarty syntax.
{if isset($GLOBAL_Error) }
How can i do this?
I got response that this is Twig template engine :S
By default, smarty use { and } as delimiters. So, you can write code:
{if $GLOBAL_Error}{/if}
But delimiters could be changed to %% and code must be in such form:
%%if $GLOBAL_Error%%%%/if%%
See also: http://www.smarty.net/docsv2/en/language.escaping.tpl
It might be, but it might not be. Smarty tag delimiters are configurable, so it's possible the developer set them to %% and %%. GLOBAL_Error may not be a variable, but a function call with no parameters. In that case, you'd need something like:
%%if (%%GLOBAL_Error%%) %%
That's some pretty ugly syntax though. It could be anything, maybe a string token for some search/replace before or after the template is compiled. If you're already using Smarty with standard delimiters, then it's unlikely that %%GLOBAL_Error%% is meant to be parsed by Smarty - it might even be a mistake or relic of old code. The only way to know for sure is to ask the author or just look at the codebase.

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