|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
shahab82 Smarty n00b
Joined: 18 Nov 2017 Posts: 4
|
Posted: Mon Dec 18, 2017 9:08 am Post subject: google translation button gives smarty comilation error |
|
|
Hi,
I am trying to add translation button on my website. Below is code.
Code: |
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> |
I am getting smarty compilation error
Code: | Syntax error in template "modules/mymodule/views/templates/front/mymodule.tpl" on line 78 "new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');" - Unexpected ": ", expected one of: "}" |
.
Any solution?
-Thanks |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Dec 18, 2017 10:05 am Post subject: |
|
|
A Smarty template requires that one observe the following requirement:
Smarty uses braces for itself.
If braces are needed for other reasons, such as javascript or CSS, they must have interior whitespace, or the code be enclosed in {literal} and {/literal} tags.
Code: | {literal}<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>{/literal} | or Code: | <script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{
pageLanguage: 'en',
layout: google.translate.TranslateElement.InlineLayout.SIMPLE
},
'google_translate_element'
);}
</script> |
|
|
Back to top |
|
shahab82 Smarty n00b
Joined: 18 Nov 2017 Posts: 4
|
Posted: Mon Dec 18, 2017 12:21 pm Post subject: |
|
|
Many thanks. It works |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Dec 19, 2017 2:42 am Post subject: |
|
|
No need to be overzealous with formatting, enough that you insert a space between "{" and following letter to escape Smarty parser.
However, a better approach would be to either use {literal} block or wrap code into a function.
I'm using {include … inline} and keeping each insert in its own file, wrapped in {literal}'s if necessary. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|