Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Marshall Salinger
All you should have to do is set a var in your include statement.

{include file="header.tpl" $jqueryWhatever=1}

And then in your header, use:

{if isset($jqueryWhatever)}



{/if}

Then you can call each individual script on a per template basis.

-Marshall


-Original Message-
From: [EMAIL PROTECTED] [<a  rel="nofollow" href="mailto:[EMAIL">mailto:[EMAIL</a> PROTECTED] On
Behalf Of Chris Scott
Sent: Wednesday, February 14, 2007 8:55 AM
To: jQuery Discussion.
Subject: Re: [jQuery] Using jQuery and Smarty

Mike Alsup wrote:
>> Sticking it in the template file would mean putting the
>> script block outside the head which I don't really want.
> 
> Why does it mean that?  I put all that stuff in the template like
this:
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "<a  rel="nofollow" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"</a>;>
> <html xmlns="<a  rel="nofollow" href="http://www.w3.org/1999/xhtml"">http://www.w3.org/1999/xhtml"</a>; xml:lang="en" lang="en">
> <head>
> <script type="text/javascript" src="js/jquery-pack.js">
> 
> {literal}
> $(function() {
> $('div.round').corner();
> });
> {/literal}
> 
> {if $googleMaps}
> 
> 
> {/if}
> {if $thickbox}
>  href="css/thickbox.css" />
> 
> {/if}
> ...

Sorry, I should have noted I'm using a common header template file for 
all pages that gets included in the page template.  Something like this 
in a page template:
{include file="header.tpl"}
[page content here]
{include file="footer.tpl"}

I'm using the {if} statements to include the js files I need based on a 
variable I set in the PHP file like you have above.  Where I'm stuck is 
now to set the js needed for the jQuery code into the HEAD.

I guess I could use something like this in header.tpl
{if $jquerycode}

$jquerycode

{/if}

and set $jquerycode in my PHP file.

-- 
Chris Scott
Adaptive Hosting Solutions, Inc.  | Blogzerk - blog hosting
http://www.adaptivehostingsolutions.com/  | http://www.blogzerk.com/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Allan Mullan
And if you want to put a script in the  I just have a piece of 
javascript:

// Add something to  (good for when using templates etc)
var  addToHead = function(type, url) {
var a;

switch(type) {
case 'script':
a = document.createElement('script');
a.setAttribute('src', url);
a.setAttribute('type', 'text/javascript');
a.setAttribute('defer', true);

break;

case 'css':
case 'style':
a = document.createElement('link');
a.setAttribute('href', url);
a.setAttribute('rel', 'stylesheet');
a.setAttribute('type', 'text/css');

break;
}

try {
document.getElementsByTagName('head')[0].appendChild(a);

a =  null;
} catch(e) {
setTimeout(function() {
addToHead(type, url);
}, 100);
}
}

You can then call addToHead('script', '/js/foo.js'); from any template.

Works perfectly for me :-) (and yeah I'm sure it could be jquery-fied 
but I just haven't done)

Allan


Chris Scott wrote:
> I'm still a newbie to jQuery so until now I've been using standard HTML 
> pages to try out new code.  Now, I need to integrate some jQuery into a 
> site that uses Smarty templates.  I'd appreciate any suggestions on how 
> people are using jQuery and Smarty.
>
> My main sticking point right now is where/how to put the jQuery code for 
> the page.  Sticking it in the template file would mean putting the 
> script block outside the head which I don't really want.  To keep it in 
> the PHP file, I think I'd need to set it as a template variable that 
> outputs it to the head.  This is the way I'm leaning, but I'm not sure 
> this is the best way to do it.
>
> Thanks.
>
>   

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Jake McGraw
I don't see why this would be an issue, if you've always used
variables within PHP to determine javascript file inclusion in Smarty,
why not do the same for javascript written using jQuery?

- jake

On 2/14/07, Chris Scott <[EMAIL PROTECTED]> wrote:
> Mike Alsup wrote:
> >> Sticking it in the template file would mean putting the
> >> script block outside the head which I don't really want.
> >
> > Why does it mean that?  I put all that stuff in the template like this:
> >
> >  > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> > http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> > 
> > 
> > 
> > {literal}
> > $(function() {
> > $('div.round').corner();
> > });
> > {/literal}
> > 
> > {if $googleMaps}
> > 
> > 
> > {/if}
> > {if $thickbox}
> >  > href="css/thickbox.css" />
> > 
> > {/if}
> > ...
>
> Sorry, I should have noted I'm using a common header template file for
> all pages that gets included in the page template.  Something like this
> in a page template:
> {include file="header.tpl"}
> [page content here]
> {include file="footer.tpl"}
>
> I'm using the {if} statements to include the js files I need based on a
> variable I set in the PHP file like you have above.  Where I'm stuck is
> now to set the js needed for the jQuery code into the HEAD.
>
> I guess I could use something like this in header.tpl
> {if $jquerycode}
> 
> $jquerycode
> 
> {/if}
>
> and set $jquerycode in my PHP file.
>
> --
> Chris Scott
> Adaptive Hosting Solutions, Inc.  | Blogzerk - blog hosting
> http://www.adaptivehostingsolutions.com/  | http://www.blogzerk.com/
>
> ___
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Mike Alsup
> Sorry, I should have noted I'm using a common header template file for
> all pages that gets included in the page template.  Something like this
> in a page template:
> {include file="header.tpl"}
> [page content here]
> {include file="footer.tpl"}

I see.  I'm doing the opposite and letting the smarty template drive
everything.  In fact, in my case I have a single tpl that drives an
entire site.  Can't you just add the {$if jquery} stuff into
header.tpl?

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Chris Scott
Mike Alsup wrote:
>> Sticking it in the template file would mean putting the
>> script block outside the head which I don't really want.
> 
> Why does it mean that?  I put all that stuff in the template like this:
> 
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> 
> 
> 
> {literal}
> $(function() {
> $('div.round').corner();
> });
> {/literal}
> 
> {if $googleMaps}
> 
> 
> {/if}
> {if $thickbox}
>  href="css/thickbox.css" />
> 
> {/if}
> ...

Sorry, I should have noted I'm using a common header template file for 
all pages that gets included in the page template.  Something like this 
in a page template:
{include file="header.tpl"}
[page content here]
{include file="footer.tpl"}

I'm using the {if} statements to include the js files I need based on a 
variable I set in the PHP file like you have above.  Where I'm stuck is 
now to set the js needed for the jQuery code into the HEAD.

I guess I could use something like this in header.tpl
{if $jquerycode}

$jquerycode

{/if}

and set $jquerycode in my PHP file.

-- 
Chris Scott
Adaptive Hosting Solutions, Inc.  | Blogzerk - blog hosting
http://www.adaptivehostingsolutions.com/  | http://www.blogzerk.com/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Using jQuery and Smarty

2007-02-14 Thread Mike Alsup
> Sticking it in the template file would mean putting the
> script block outside the head which I don't really want.

Why does it mean that?  I put all that stuff in the template like this:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">



{literal}
$(function() {
$('div.round').corner();
});
{/literal}

{if $googleMaps}


{/if}
{if $thickbox}


{/if}
...

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] Using jQuery and Smarty

2007-02-14 Thread Chris Scott
I'm still a newbie to jQuery so until now I've been using standard HTML 
pages to try out new code.  Now, I need to integrate some jQuery into a 
site that uses Smarty templates.  I'd appreciate any suggestions on how 
people are using jQuery and Smarty.

My main sticking point right now is where/how to put the jQuery code for 
the page.  Sticking it in the template file would mean putting the 
script block outside the head which I don't really want.  To keep it in 
the PHP file, I think I'd need to set it as a template variable that 
outputs it to the head.  This is the way I'm leaning, but I'm not sure 
this is the best way to do it.

Thanks.

-- 
Chris Scott
Adaptive Hosting Solutions, Inc.  | Blogzerk - blog hosting
http://www.adaptivehostingsolutions.com/  | http://www.blogzerk.com/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/