Zen Follower
- Join Date:
- May 2010
- Posts:
- 222
- Plugin Contributions:
- 0
Post #1 by commdiver
Is there a way to add JavaScript to the Blank Sidebox module? If not, is there any other way to add JavaScript to a sidebox?
Started by commdiver on 2 Feb 2011, 2:51 PM · Views: 4,747
Zen Follower
Is there a way to add JavaScript to the Blank Sidebox module? If not, is there any other way to add JavaScript to a sidebox?
Black Belt
Zen Follower
Thank you! That worked.
Zen Follower
Hi.
I'm resurrecting this because I'm trying to accomplish the same or at least similar goal.
As soon as I start adding php and java to tpl_blank_sidebox.php OR blank_sidebox_defines.php my site goes blank(ah! I guess it's going it's job ;))
So my questions are:
-All the posts I've found imply the solution is to escape single quotes. I've tried that. Perhaps some need escaping and others don't...I really don't know. But I know if I escape them all the site still goes blank.
-I've read to avoid putting java in the defines so how do I add it properly?
Here's the codes I'm trying to insert:
<div id="footer-payments">
<center>
<img src="<?php echo $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images').'/'.FOOTER_PAYMENT_ICON ?>" alt="payments we accept" class="payments-image" />
</center>
</div>
<script type="text/javascript">
(function() {
var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
})();
</script>
<!-- Do not alter for the seal to work properly -->
<div id="sslsSiteSeal">
seal by <a href="http://ssls.com/">SSLs.com</a>
</div>
I've returned both my defines and tpl files to stock at this point.
My dev site is:
dev DOT littlecloset DOT ca
Black Belt
Blank pages generally result from PHP errors and create error log files in your /logs folder. Post the contents of the most recent one here.
Black Belt
In general, you would put the script (without <script type="text/javascript"> </script> tags) in a new file named like jscript_siteseal.js, saved in /includes/templates/your_template/jscript/. You can name it as you like as long as it starts with jscript_. ```
(function() {
var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
})();
I'm not sure if the ( before function and the )() at the end are good to have there. Someone proficient in javascript would know.
The rest of the code you show would go into either the sidebox define file or tpl_ file. In the tpl_ file, you would assign it to $content like
```php
$content .= '<div id="footer-payments">
<center>
<img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,\'images\') . '/' . FOOTER_PAYMENT_ICON" alt="payments we accept" class="payments-image" />
</center>
</div>';
$content .= ' <!-- Do not alter for the seal to work properly -->
<div id="sslsSiteSeal">
seal by <a href="http://ssls.com/">SSLs.com</a>
</div>';
I have edited the coding format to function correctly in the particular context.
Black Belt
Missed one :)
This bit
$template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images')
needs either the first '' (two single quotes) escaped (''), or the second set 'images' not escaped ('images'); I forget which at the moment... think the escapes are not needed here. Try it both ways.
Zen Follower
Try it both ways.
Didn't help.
Question; is the code suppose to be a continuous line?
Zen Follower
In case this will help, here's an entry in the logs I suspect is related to the code:
[15-May-2014 10:09:01 America/New_York] PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/littlecl/HIDDEN/dev/includes/templates/piccadilly_posh/sideboxes/tpl_blank_sidebox.php on line 19
Line 19 is:
$content .= '<div id="footer-payments">
Black Belt
If you use line breaks in the define, they will show in the "view source" of your output. They will not break a define unless you are doing something else wrong.
One of the escaping options will work while the other won't. This means you have some other error in your code. Post your tpl_blank_sidebox.php so we can see exactly how you are adding the content. Also, exactly what you did with the javascript and where.
Zen Follower
Thanks for your help.
Here my whole tpl_blank_sidebox.php @ my_template/sideboxes/
<?php
/**
* blank sidebox - allows a blank sidebox to be added to your site
*
* @package templateSystem
* @copyright 2007 Kuroi Web Design
* @copyright Portions Copyright 2003-2007 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: blank_sidebox.php 2007-05-26 kuroi $
*/
$content = '';
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
// Replace the text and HTML tags between the apostophes on lines 19 and 20.
// Use as many or as few lines using this model as you need for your custom content.
// If you have a multilingual site define your text in the languages/YOUR_LANGUAGE/extra_definitions/blank_sidebox_defines.php and include it as shown in line 19.
// If your site is monolingual, you can put the text right here as shown on line 20 (and nobody will know!)
$content .= '<div id="footer-payments">
<center>
<img src="' . $template->get_template_dir(\'\',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON" alt="payments we accept" class="payments-image" />
</center>
</div>';
$content .= ' <!-- Do not alter for the seal to work properly -->
<div id="sslsSiteSeal">
seal by <a href="http://ssls.com/">SSLs.com</a>
</div>';
?>
And here's my jscript_sslseal.js @ my_template/jscript/
(function() {
var ss = document.createElement('script'); ss.type = 'text/javascript'; ss.async = true;
ss.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'seal.ssls.com/script.js?cn=' + window.location.host;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ss, s);
})();
Zen Follower
Just for kicks I commented out the payments icons to focus merely on the site seal and the site seal actually works. The positioning is way off but I'm confident I can figure that out on my own. Then I tried the same with the payment icons and even alone, that code breaks the site. One thing I noticed, which is odd to me because that same code worked when it was in the footer, the path is actually images/icons/ not just images. Is it just that perhaps?
Black Belt
You have php <img src="' . $template->get_template_dir(\'\',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON" with one escaped set of quotes '' and one unescaped set 'images'. This is guaranteed to fail. Try ```php
<img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"
Zen Follower
Well, that was just leftovers from your suggestion in post #7. As was already suggested, I tried with both single quotes & either escaped. None of those options have worked. I also just tried the latest suggest method:
<img src="' . $template->get_template_dir('',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON"
to no avail.
Zen Follower
Although I've been copying/pasting perhaps there must be a mistake somewhere!? Here are the contents as is directly from my tpl_blank_sidebox.php:
<img src="' . $template->get_template_dir(''',DIR_WS_TEMPLATE, $current_page_base,'images') . '/' . FOOTER_PAYMENT_ICON" alt="payments we accept" class="payments-image" />
Zen Follower
I think I mentioned this already but...Seems to me the images couldn't show up because they're actually in a subfolder of images ie images/icons. Seems to me like that code is only looking for the image files in 'images' no? What contradicts that is that this exact code was functioning in the footer...I just don't understand php enough yet so....
Sorry, I don't know what lead me to think the images were in a subfolder but they are not.
Zen Follower
Before anyone wastes more energy on this...
I gave up on the blank_sidebox in lieu of PayPal CreditCards Accepted. I simply split the siteseal snippet between the tpl_paypal_creditcards_sidebox.php and jscript as suggested earlier in this thread.
$content = '';
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
$content .= ' <!-- Do not alter for the seal to work properly -->
<div id="sslsSiteSeal">
seal by <a href="http://ssls.com/">SSLs.com</a>
</div>';
$content .= '<p>' . TEXT_PAYPAL_CREDITCARDS_SIDEBOX . '</p>';
$content .= '</div>';
Don't know why we couldn't get things going with the previous add-on but perhaps by posting this code it may be obvious to someone.
Thank you to everyone who tried so hard to get this working. Much appreciated.
Black Belt
$template->get_template_dir(''',DIR_WS_TEMPLATE,
``` You have three single quotes here instead of two. If this is what was actually in your live file, it would cause an error due to the extra quote.
Zen Follower
For what it's worth I had caught that to and removing the third single quote didn't fix the code. I suspect there is something outside the snippets I've shown that was effecting things.
Black Belt
Without seeing the exact error message and the exact file content that accompanied it, it is only possible to guess.
Tell staff why this post should be reviewed.