Why doesn't 'text{$variable}' work for me? - smarty

I'm using the latest stable version of Smarty and can't get this string to work. I've looked at other questions for solution to do this but none seem to work.
This is a template file (TPL), and doesn't contain any PHP at all. Note that the TPL file is compiled to a PHP script and then sent to the browser. It's not a PHP file.
Current code:
'foo{$bar}'
which outputs as:
'foo{$bar}'
instead of the value of $bar.
What am I doing wrong?

If you use any variables within text you have to use double-quotes " instead of single quotation marks '. Text within single quotation marks is not parsed for variables in PHP.

Related

wget is not working with special parameter

I am trying to download a file from this link with wget.
https://sfirmware.com/downloads/downloader.php?fileid=257457&hash=458cd40aa7824c3d25fe096c0b01d4b7
I am aware that & is a special character in shell environment.
So far i've tried double quote,single quote ,putting %26 replacing '&' (as per some suggestion) but the solution doesn't seem to work with this error-
Hash not exist in db!Back to Home Page
It seems the hash number from the link is ignoring while requesting.
How do I modify the code to download this file with wget?

Converting a TXT file with double quotes to a pipe-delimited format using sed

I'm trying to convert TXT files into pipe-delimited text files.
Let's say I have a file called sample.csv:
aaa",bbb"ccc,"ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","nnn"ooo,ppp"qqq",rrr" sss,"ttt,""uuu",Z
I'd like to convert this into an output that looks like this:
aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z
Now after tons of searching, I have come the closest using this sed command:
sed -r 's/""/\v/g;s/("([^"]+)")?,/\2\|/g;s/"([^"]+)"$/\1/;s/\v/"/g'
However, the output that I received was:
aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|pppqqq|rrr" sss|ttt,"uuu|Z
Where the expected for the 9th column should have been ppp"qqq" but the result removed the double quotes and what I got was pppqqq.
I have been playing around with this for a while, but to no avail.
Any help regarding this would be highly appreciated.
As suggested in comments sed or any other Unix tool is not recommended for this kind of complex CSV string. It is much better to use a dedicated CSV parser like this in PHP:
$s = 'aaa",bbb"ccc,"ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","nnn"ooo,ppp"qqq",rrr" sss,"ttt,""uuu",Z';
echo implode('|', str_getcsv($s));
aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|nnnooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z
The problem with sample.csv is that it mixes non-quoted fields (containing quotes) with fully quoted fields (that should be treated as such).
You can't have both at the same time. Either all fields are (treated as) unquoted and quotes are preserved, or all fields containing a quote (or separator) are fully quoted and the quotes inside are escaped with another quote.
So, sample.csv should become:
"aaa""","bbb""ccc","ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","""nnn""ooo","ppp""qqq""","rrr"" sss","ttt,""uuu",Z
to give you the desired result (using a csv parser):
aaa"|bbb"ccc|ddd,eee|fff|ggg,hhh,iii|jjj kkk|lll" mmm|"nnn"ooo|ppp"qqq"|rrr" sss|ttt,"uuu|Z
Have the same problem.
I found right result with https://www.papaparse.com/demo
Here is a FOSS on github. So maybe you can check how it works.
With the source of [ "aaa""","bbb""ccc","ddd,eee",fff,"ggg,hhh,iii","jjj kkk","lll"" mmm","""nnn""ooo","ppp""qqq""","rrr"" sss","ttt,""uuu",Z ]
The result appears in the browser console:
[1]: https://i.stack.imgur.com/OB5OM.png

change file extension with a ruby script

I'm trying to change the exstension of a file passing the arguments by console
system = "rename" , "'s/\#{ARGV[0]}$/\#{ARGV[1]}'", "*#{ARGV[1]}"
The code is correct because it works on console but when I put it in a script I have trouble with
s/\#
because it appears in pink and the console does not get it.
you don't want to send literal single quotes, so remove them.
you want to remove the backslashes so you let Ruby evaluate those expressions.
you're missing the trailing slash.
what's that equal sign doing?
did you want ARGV[0] in the last argument to rename, instead of ARGV[1]?
you want to use * wildcard, which requires a shell to expand into a list of files, which means you can't use the list form of system
Try
system "/usr/bin/rename -n 's/#{ARGV[0]}$/#{ARGV[1]}/' *#{ARGV[0]}"
Remove the -n option if it looks like you're going to rename the way you want.
And, of course, you don't need to call out to the shell for this:
Dir.glob("*#{ARGV[0]}").each {|fname|
newname = fname.sub(/#{ARGV[0]}$/, ARGV[1])
File.rename(fname, newname)
}

How to output file name inside system(git log) command in ruby script?

The problem I encounter is that I don't manage to put the name of the file inside the below screen output inside git log using pretty format flag.
An extract of my code is the following:
filename = File.basename file
system('git log --pretty=format:"%cd: (here I want the filename)"')
presented as sample.c for example.
I tried #{filename} but is interpreted as a string from the compiler and the result is the same as the input.
Thank you in advance.
It is interpreting it as a string because single quotes do now allow string interpolation.
system('git log --pretty=format:"%cd: (here I want the filename)"')
You can change this to use double quotes so you can take advantage of interpolation and escaping.
system("git log --pretty=format:\"%cd: #{filename}\"")
https://ruby-doc.org/core-2.1.1/doc/syntax/literals_rdoc.html

Magento: Single Quotes in Translation Files Void Translation

I am trying to translate some strings from a Magento 1.5.x install and it works fine when there is a double quote, but I cannot properly escape single quotes.
"Hello, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>","Hello, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>","Olá, <strong>\'.Mage::getSingleton(\'customer/session\')->getCustomer()->getName().\'!</strong>"
"<button class=""form-button"" onclick=""setLocation(\'%s\')"" type=""button""><span>Login or Register</span></button>","<button class=""form-button"" onclick=""setLocation(\'%s\')"" type=""button""><span>Login ou Cadastro</span></button>"
I've tried the original string as is, and escaped with a backslash. I've tried the translated string escaped with a backslash and double single quotes.
I tried searching the magento forum, but the only two people that posted about this problem got no replies.
When you escape a single-quote with a backslash in the .phtml file, you need to remove the backslash from the translation string in the .csv file.
Example:
<?php echo $this->__('Click here to print a copy of your order confirmation.', $this->getPrintUrl())
Should be in .csv file:
"Click here to print a copy of your order confirmation.", "Click here to print a copy of your order confirmation."
without the backslashes, otherwise the string won't get translated. As usual double-quotes in the .csv have to be escaped with another double-quotes.
Some .csv translation files in Magento 1.7.0.2 still have these backslashes before single-quotes, which is a minor bug that needs to be fixed.
Try this
Other option is that you can put error message in double quotes as
__("Please specify the product's option(s).");
and in translation file you make it by simple this
Colum ONE | Colum Two
Please specify the product's option(s). | TRANSLATION OF that FILE
remove \ from Translation file and from code make it DOUBLE QUOTES in stead of single quote.
It turns out that the way the strings were being output in PHP were not compatible with Magento's translation engine. The fix comprised changes in the PHP file, not in the syntax of the translation files. The PHP files now read:
echo $this->__('Hello') . ', <strong>'.Mage::getSingleton('customer/session')->getCustomer()->getName().'!</strong>';
echo ('<button class="form-button" onclick="setLocation(\'' . $this->getUrl('customer/account/login') . '\')" type="button"><span>') . $this->__('Login or Register') . '</span></button>';
as opposed to having everything inside one echo $this->__('String to be translated . phpcode. String to be translated . phpcode . etc . etc')
You should never put html in a translated string. Magento uses vsprintf (http://php.net/manual/en/function.vsprintf.php) so it's easy to add a variable to a translation like this:
echo '<strong>'.$this->__('Hello %s!',Mage::getSingleton('customer/session')->getCustomer()->getName()).'</strong>';
In this way you can then translate easily in a csv: "Hello %s","Hola %s"

Resources