Learning to build blocks

Permalink
I have decided to learn how blocks work, also read the documentation regarding blocks and I plan to attempt to build a block based on jQuery Lighboxhttp://leandrovieira.com/projects/jquery/lightbox/...

I am trying to add this jQuery function
<script type="text/javascript">
    $(function() {
        $('#gallery a').lightBox();
    });
    </script>


so I had a look into the controller.php file in the Zoom Content block by Remo, and tried using the

$v->addHeaderItem('<script type="text/javascript">$(document).ready(function() { $('gallery a').lightBox directory:"'.$uh->getBlockTypeAssetsURL($bt).'/images"}); });</script>','CONTROLLER');


but seems like there is a Parse error, sorry but i am NUB at both Php and Jquery. Pointers where i am going wrong would be helpful.

 
jordanlev replied on at Permalink Reply
jordanlev
Looks like you have conflicting quotes in your string. This happens all the time and can be very confusing (especially when you have one programming language inside another -- javascript inside php in this case).
There are two different ways to quote strings in php (and javascript) -- single quotes, or double quotes. What you want to do is pick one to use for php and another to use for the javascript inside the php. I personally find that using the single quotes for php and double quotes for javascript works best. So in your code, what you want is this:

<?php   
$v->addHeaderItem('<script type="text/javascript">$(document).ready(function() { $("gallery a").lightBox directory:"'.$uh->getBlockTypeAssetsURL($bt).'/images"}); });</script>','CONTROLLER'); 
 ?>


(The difference is now there are double-quotes around the "gallery a")

Hope that helps!

-Jordan Lev
zoinks replied on at Permalink Reply
Great! When you're all done with this hard work, could you do us a kindness and give it away for free? :-D

I just downloaded a couple lightboxes, one of which was broken from the start. And I just realized I will have to buy a license every time I want to use one. :-( I'm used to Lightbox being free, ya know what I mean?!