Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to use Javascript codes in template files?
Goto page Previous  1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
phaitour
Smarty n00b


Joined: 10 Mar 2008
Posts: 2

PostPosted: Mon Mar 10, 2008 9:31 am    Post subject: Reply with quote

very helpful guys! Thanks!
Back to top
View user's profile Send private message
mattpro
Smarty Rookie


Joined: 10 May 2008
Posts: 8

PostPosted: Mon Jun 23, 2008 8:57 am    Post subject: Re: Reg Exp to the rescue ! Reply with quote

kilimangaro wrote:
Try these prefilters functions, they work perfectly for us:

[php]function smarty_prefilter_literal_script_and_style(&$tpl_source, &$smarty) {
$pattern[] = '~<script\b(?![^>]*smarty)(.*)</script>~siU';
$replace[] = '<!-- {literal} --><script$1 $2</script><!-- {/literal} -->';
$pattern[] = '~<style\b(?![^>]*smarty)>(.*)</style>~siU';
$replace[] = '<!--{literal}--><style$1>$2</style><!--{/literal}-->';
return preg_replace($pattern, $replace, $tpl_source);
}

class MySmarty extends Smarty {
function MySmarty() {
$this->register_prefilter('smarty_prefilter_literal_script_and_style');
}
}[/php]

It brace all <script> and <style> tags whith {litteral} so that
Code:
<script language="JavaScript" type="text/JavaScript">
<!--
function doSomeJS() {
   // blabla ...
}
-->
</script>

... give ...
Code:
<!--{literal}--><script language="JavaScript" type="text/JavaScript">
<!--
function doSomeJS() {
   // blabla ...
}
-->
</script><!--{/literal}-->

... but ...
Code:
<script language="JavaScript" type="text/JavaScript" smarty>
<!--
showMyLayer1 = {$smarty.get.id|intval}
-->
</script>

... give ...
Code:
<script language="JavaScript" type="text/JavaScript" smarty>
<!--
showMyLayer1 = {$smarty.get.id|intval}
-->
</script>

Wondefull! isn't? Wink


Thanks that worked great.
Back to top
View user's profile Send private message
student of life
Smarty n00b


Joined: 09 Sep 2008
Posts: 3

PostPosted: Tue Sep 09, 2008 7:22 am    Post subject: Reply with quote

thanks. i'm learning a lot of information here.
Back to top
View user's profile Send private message
manfred
Smarty Rookie


Joined: 07 Oct 2008
Posts: 10

PostPosted: Tue Nov 18, 2008 6:09 pm    Post subject: {include file=style.css} Reply with quote

is it possible in smarty?
Now i am usin this code to include style sheet but not working
in .tpl
Code:

<style>
{literal}
{include file="style.css"}
{/literal}
</style>
<td id="reg" >Username</td>


in CSS
Code:

/* CSS Document */
#reg   {
   background-color:#0000FF;
   font:Verdana, Arial, Helvetica, sans-serif;
   width:200px;
}
if it possible please help me
thanks
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Wed Nov 19, 2008 8:01 am    Post subject: Reply with quote

Try {fetch} instead of {include}.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
manfred
Smarty Rookie


Joined: 07 Oct 2008
Posts: 10

PostPosted: Tue Nov 25, 2008 5:17 pm    Post subject: Reply with quote

When i use fetch i got this error
Fatal error: Smarty error: [plugin] fetch cannot read file 'style.css'
Back to top
View user's profile Send private message
manfred
Smarty Rookie


Joined: 07 Oct 2008
Posts: 10

PostPosted: Tue Nov 25, 2008 5:18 pm    Post subject: Reply with quote

Thank you for the reply
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Mon Dec 22, 2008 3:29 pm    Post subject: Reply with quote

my delimiters are

<{ and }> and I've never run into problems.
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Thu Jan 15, 2009 10:46 am    Post subject: Use unobstrusive javascripts Reply with quote

Try to write ALL of you java scripts in an external file and use them in an unobtrusive manners.
Back to top
View user's profile Send private message Visit poster's website
muhammad
Smarty Rookie


Joined: 07 May 2009
Posts: 5

PostPosted: Fri May 08, 2009 5:36 am    Post subject: Re: How to use Javascript codes in template files? Reply with quote

hbilgen wrote:
Hi,

I'm using javascript codes in my template files, but Smarty recognizes function curly braces '{' of functions as variables and gives error.

How to use those javascript function codes in template files?

Put your javascript code in between {literal}{/literal}
Back to top
View user's profile Send private message
jonemere
Smarty n00b


Joined: 04 Jan 2010
Posts: 3

PostPosted: Tue Jan 05, 2010 6:32 am    Post subject: Reply with quote

Thanks for the posting, It is really helpful to me.
Your post is very interesting and I teach something new over here. Nice information.
My heartiest thanks for sharing.
_________________
2.5 hdd
Back to top
View user's profile Send private message Send e-mail
mrghost18
Smarty n00b


Joined: 06 May 2010
Posts: 2

PostPosted: Thu May 06, 2010 6:05 am    Post subject: Reply with quote

Can anyone say how to fetch all datas from a database in smarty and show them in a table? Question
Back to top
View user's profile Send private message
chefkoch666
Smarty n00b


Joined: 15 May 2010
Posts: 2

PostPosted: Sat May 15, 2010 7:22 am    Post subject: Thank you Reply with quote

Really helpful sticky!
Thanks a lot!

@mrghost18: Please see on the left homepage navigation Get Help! -> Sample Application, especially page 5 and previous. You have to fetch data with php or whatever language you are using and then iterate through the array with foreach.

Best regards,
Marek
Back to top
View user's profile Send private message
hazelbates98
Smarty n00b


Joined: 21 Oct 2011
Posts: 1
Location: Sydney, NSW

PostPosted: Fri Oct 21, 2011 8:17 am    Post subject: Gratitude Reply with quote

Thank you for the wonderful information shared. It is very useful.
Back to top
View user's profile Send private message
Juggler
Smarty n00b


Joined: 05 Dec 2012
Posts: 1

PostPosted: Wed Dec 05, 2012 10:13 am    Post subject: What are the best delimeters then? Reply with quote

What are the best delimeters then?

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

Obviously to hide them from html developers/designers and not interfere with javascript?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 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