Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Javascript on 1 Document General page only

Javascript on 1 Document General page only

Locked

Views: 2,207

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
18 Apr 2008, 6:47 AM
#1
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Javascript on 1 Document General page only

Ok, I have added a flash video player to my site using the "Document General" category. The player and playlists work great.

The problem is that I had to add some javascript to the "tpl_document_general_info_display.php" page and now the buttons for my playlists show up on ALL of my Document General pages. Is there some code I can add to the php page to make the javascript only show on one specific page? Possibly by the "id"?

Here is the working page:
http://www.thebasher.com/index.php?main_page=document_general_info&cPath=15_17&products_id=33

And here is a link (one of many) to a page that I don't want the javascript to load on but as of now it does:
http://www.thebasher.com/index.php?main_page=document_general_info&cPath=15_16&products_id=35

I placed the code in the tpl_document_general_info_display.php to show up on the bottom of the page.

If anyone has a fix I would greatly appreciate it.

Thanks!

20 Apr 2008, 12:17 AM
#2
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

Anyone have a suggestion or fix?

20 Apr 2008, 3:03 AM
#3
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Javascript on 1 Document General page only

Unfortunately, due to the way templates are generated, you don't have many options in the realm of non-hack workarounds.

The simplest solution would be to wrap the inclusion of your flash player in an if statement. The contents of the if statement would be the products_id values that match each product where the player should be displayed. Based on your posts, here's an example that assumes you only have the player on one product:

if ($_GET['products_id'] == 33) {
  // include your javascript here
}
20 Apr 2008, 3:49 AM
#4
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

Hey Blindside. Thanks for the reply. I figured that I would need to include and "if" statement. However, it didn't work. Here is a snippet of the code where I put the "if" statement. I am possibly, and most likely, doing it wrong.

Nice blog. The "Do Search Stats Dictate Your Agenda?" post was excellent. I couldn't agree more!

[CODE]<!--bof Additional Product Images -->

<?php /** * display the products additional images */ require($template->get_template_dir('/tpl_modules_additional_images.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_additional_images.php'); ?> <!--eof Additional Product Images -->

if ($_GET['products_id'] == 33) {

<p align="center"> <button onclick="javascript:createplayer('http://www.thebasher.com/mediaplayer/playlist_featured.xml', true)">Featured Videos<br /> <img src="http://www.thebasher.com/mediaplayer/basher_tv/playlist_images/featured_video.jpg" alt="Featured Videos" width="100" height="100" /></button>
20 Apr 2008, 3:55 AM
#5
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

For some reason I am not able to include all of the code so I made an attachment instead.
Attachment #3806

20 Apr 2008, 4:37 AM
#6
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Javascript on 1 Document General page only

I can't tell from your post or your attachment exactly what your code looks like (the attachment is full of backslashes and hex code). However, I am guessing that you're not closing the php tags before outputting your html. Here's a clearer example:

<!--bof Additional Product Images -->
<?php
/**
* display the products additional images
*/
require($template->get_template_dir('/tpl_modules_additional_images.php',DIR_WS_TEMPLATE , $current_page_base,'templates'). '/tpl_modules_additional_images.php'); ?>
<!--eof Additional Product Images -->

if ($_GET['products_id'] == 33) {
[B]?>[/B]
<p align="center">
<button onclick="javascript:createplayer('http://www.thebasher.com/mediaplayer/playlist_featured.xml', true)">Featured Videos<br />
<img src="http://www.thebasher.com/mediaplayer/basher_tv/playlist_images/featured_video.jpg" alt="Featured Videos" width="100" height="100" /></button>
[B]<?php
// continue with php code...[/B]
?>

Note the stuff highlighted in red.

Thanks for the blog kudos! :smile:

20 Apr 2008, 7:47 AM
#7
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

I apologize for the text file. For some reason I'm having a bad night getting an example posted on the forum. (I've been tracking drums all night and tried to do it quick between takes)

So I took a screen shot. Hopefully this works...

Thanks for all of your help. I really appreciate it.
Attachment #3807

20 Apr 2008, 3:14 PM
#8
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Javascript on 1 Document General page only

Yep, it's exactly what I thought. You need to jump out of PHP in order for the javascript to show up in the body of the page. Follow the highlighted instructions in my last message and you should get it working.

20 Apr 2008, 11:42 PM
#9
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

Ok, so I added the code but the buttons still show up on all of the Document General pages.

Since I'm not the sharpest with php I'm thinking about customizing the "Document Product" category since I don't use that for anything else. That way the buttons for my video playlists will only show up on that one specific page.

I do appreciate all of your help. Plus I found a new blog (subscribed to it today) to read.

Thanks Blindside!

21 Apr 2008, 1:48 PM
#10
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
1

Re: Javascript on 1 Document General page only

Your code is in as right a place as any, I wouldn't bother moving it. The logic is the problem. Try adding single quotes around the number in the if statement. Like this:

if ($_GET['products_id'] == [B]'33'[/B]) {
  // include your javascript here
}
21 Apr 2008, 6:46 PM
#11
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

At work right now. I'll try that when I get home tonight.

Thanks!

26 Apr 2008, 1:42 AM
#12
guysoul avatar

guysoul

New Zenner

Join Date:
Mar 2008
Posts:
26
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

Hi there.. can anyone help me on these regarding inserting javascript on my homepage? I want to integrate virtual smart agent on my home page and the instructions on virtual smart agent is that i need to put the code before the end </body> tag. But as i go to the index.php of my shop root folder, i could not find any end body tag.. Can anyone help me where to put the script coz there are lots of files in zencart.

My site is https://bestmilagechip.com, I want the virtual smart agent integrated on the homepage.. tnx please.... looking forward to your response.. :lamo:

27 Apr 2008, 8:39 AM
#13
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

Look in the docs folder that came with your zen-cart install and there are two files that will tell you where you need to insert the code. The two files are:
"read_me_jscript.html" and "read_me_onload.html".

These files really helped me with adding javascript to my pages. You'll have to create a page that contains your jscrpt code and I believe you will need to put it in:
includes/modules/pages/index

Not 100% sure on that so if someone else could confirm that would be great.

28 Apr 2008, 3:52 AM
#14
thebasher avatar

thebasher

New Zenner

Join Date:
Dec 2007
Posts:
53
Plugin Contributions:
0

Re: Javascript on 1 Document General page only

BlindSide,
Thanks for all your help. Unfortunately I didn't have any luck getting the javascript to work correctly on the document_general pages so I decided to modify my document_product page for the time being since I'm not using that category.

I'm going to try it again when I have some extra time though because it drives me nuts when I can't figure something out.

Again, thank you, than you, thank you.