Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

How to use Javascript codes in template files?
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7360
Location: Lincoln Nebraska, USA

PostPosted: Wed Dec 05, 2012 2:38 pm    Post subject: Re: What are the best delimeters then? Reply with quote

Juggler wrote:
What are the best delimeters then?

What I've seen
{{ }}
{# #}
<{ }>

Obviously to hide them from html developers/designers and not interfere with javascript?


The best delimiters are { }

Use Smarty 3 and put whitespace around them, and Smarty 3 ignores them.

Code:
<script>
function foo {  // smarty ignores this
    return;
} // this too
</script>
Back to top
View user's profile Send private message Visit poster's website
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 90

PostPosted: Fri Dec 07, 2012 3:20 pm    Post subject: Reply with quote

Mohrt, what about ending javascript delimiters with }; ?
Must that be ' };' or ' } ;' or ' }; ' to get ignored?
I always took the last and that seems to work, but I would like to know exactly.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7360
Location: Lincoln Nebraska, USA

PostPosted: Fri Dec 07, 2012 3:24 pm    Post subject: Reply with quote

" } ;" would get ignored.

[edit] double check with Uwe, but }; might get ignored to, or }[anything]. you can test in a template and see what you get as well.
Back to top
View user's profile Send private message Visit poster's website
Aristophan
Smarty Regular


Joined: 10 Jan 2011
Posts: 90

PostPosted: Fri Dec 07, 2012 4:35 pm    Post subject: Reply with quote

" } ;" and " };" both work fine. (...did not check for anything Wink )
edit: - and even "};" does!
Back to top
View user's profile Send private message
solidrock
Smarty n00b


Joined: 27 Apr 2016
Posts: 2

PostPosted: Wed Apr 27, 2016 5:19 am    Post subject: javascript for months Reply with quote

Hi, I am trying to make this work. You guys know why it is not working for me? I am using vTiger template.

function fechameses()
{
var d = new Date("{$RECORD.invoicedate}");
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var n = month[d.getMonth()];
} {literal} fechameses(){/literal}</script>
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 303

PostPosted: Wed Apr 27, 2016 7:26 am    Post subject: Re: javascript for months Reply with quote

All inside literal tags will be ignored by Smarty - also the Smarty var {$RECORD.invoicedate} Wink

Try this

Code:
{literal}
function fechameses()
{
var d = new Date("{/literal}{$RECORD.invoicedate}{literal}");
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var n = month[d.getMonth()];
}{/literal}
Back to top
View user's profile Send private message
solidrock
Smarty n00b


Joined: 27 Apr 2016
Posts: 2

PostPosted: Wed Apr 27, 2016 11:53 am    Post subject: Reply with quote

Thanks for replying.. and sorry for being such a noob.

I tried your suggestion but still it would give me blank and not the result.. maybe I am not calling the function correctly... this is what I have so far, What do I need to do to call the function?

<script language="JavaScript" type="text/JavaScript">
{literal}
function fechameses()
{
var d = new Date("{/literal}{$RECORD.invoicedate}{literal}");
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var n = month[d.getMonth()];
}{/literal}
fechameses()
</script>

Thanks for your help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
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
Protected by Anti-Spam ACP