|
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 |
june.shi Smarty Rookie
Joined: 11 Aug 2006 Posts: 24
|
Posted: Thu May 22, 2008 1:17 am Post subject: Smarty and jQuery |
|
|
I have a page_header.tpl contained by every page. but now, i should add jQuery ready() to my page_header.tpl, you know all the pages contains more js code, when i load a page, all the js file contained,maybe loaded. how to avoid it?
could you give me a dainty method?
sorry poor english, i hope you all understand what i said?
Sincerely,
June _________________ PHP...
PEAR...
Smarty...
jQuery... |
|
Back to top |
|
SGBoise Smarty Rookie
Joined: 28 Mar 2008 Posts: 27 Location: GamePacks.org
|
Posted: Sat May 31, 2008 11:17 pm Post subject: |
|
|
I'm not sure what exactly you want.Do you want to preventing loading the js file?
If yes here is what I do.
Code: | header.tpl:
{* Load the CCS and JS files *}
{foreach from = $tms_headerfiles item = headerfile}
{if $headerfile.type == "css"}
<link rel="stylesheet" href="/{$headerfile.file}" type="text/css" />
{elseif $headerfile.type == "js"}
<script type="text/javascript" src="/{$headerfile.file}"></script>
{/if}
{/foreach} |
Code: | Php Code:
function site_headerfiles($headerfile = "", $type = "") {
$this->writelog("Running: site_headerfiles");
// Since file isn't being added return the array
if ($headerfile == "") {
if (TMS_DEBUG == 1) {
$this->writelog("These are the header files that will be loaded:");
$this->writelog_array($this->headerfiles);
}
return $this->headerfiles;
}
// By default make the file type css
if ($type == "") {
$this->writelog("Header file type wasnt passed so assigned as css.");
$type = "css";
}
$found = false;
// Determine if this file has been added already
foreach ($this->headerfiles as $x) {
if ($x["file"] == $headerfile) {
$found = true;
break;
}
}
if ($found == false) {
// It wasnt already added
$this->headerfiles[] = array("file" => $headerfile, "type" => $type);
} else {
$this->writelog("Header file {$headerfile} already was added. Will not add it again.");
}
return;
} |
Usage:
Code: | // Load ajax header files
$this->site_headerfiles($this->paths->templateuri."ajax.js", "js");
$this->site_headerfiles($this->paths->tms_subfolderuri."prototype.js", "js"); |
I use prototype for my javascript framework for ajax. some of my pages use other frameworks depending on the media type. This way I only load the frameworks that is being used on the page. _________________ GamePacks.org - Products for the Arcade/Media Community
Video Script - The ultimate media site script
AutoVideoScript.com - Run your own youtube sharing site |
|
Back to top |
|
june.shi Smarty Rookie
Joined: 11 Aug 2006 Posts: 24
|
Posted: Tue Jun 03, 2008 6:29 am Post subject: |
|
|
Thanks...
i guess i know what i should do that tailored my needs. _________________ PHP...
PEAR...
Smarty...
jQuery... |
|
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
|