You can call the function 'share_popup_load' to load ShareThis object, the first parameter should be the share_id for the popup that you wish to load and then specify the optional second parameter as 'share_sharethis'. Once this is done you can render the ShareThis link by calling the render() method of the object, be sure to pass the $node object into the render method. Example code:
The best way to add things to .tpl's is to define a variable in your template.php file in a theme preprocess function, then all you need to do in your .tpl is to print that variable.
Hey greenSkin, thanks for the clear explanation... I've got the js call being generated and placed in my template file. Although, I'm getting a javascript error of the SHARETHIS object not being defined...
"SHARETHIS is not defined"
I've manually included the javascript files. Is there another js call I need to make to create the SHARETHIS object? Or something else I need to do?
The second parameter needs to be 'share_sharethis' (no-caps) for ShareThis and 'share' for a regular Share popup. All javascript and css files get added automatically so you shouldn't have to include them yourself.
I'm able to see the shareThis icon and the popup begins to come up (although it's empty)... However, 'share_sharethis' still gives me the same error. When I looked at the module code for "share_popup_load" I see a switch and a case for $module='share' and default case but nothing for 'share_sharethis' ...
The switch statement has been removed in the latest dev version of Share. I should also note that of course Share uses drupal_add_js and drupal_add_css to add the javascript and css files so the css and javascript won't get added to the page if the code mentioned here is actually used in a .tpl file. If the code is implemented inside of a .tpl file (which should be avoided if at all possible) the theme will have to include the needed files. The best place to implement the functionality mentioned is to put it inside of the template.php file. Check http://drupal.org/node/16383 to find out how to do this.
Thanks for the sticking with me on this. If the switch statement is removed or at least the "share_sharethis" portion in 2.0-alpha10 then how do you go about getting it to render? Do I have to call a function from the share_sharethis.module?
I actually believe my problem is coming from the code generated by gen_head() isn't being shown on my drupal page and therefore the sharethis.com widget doesn't exist. Is drupal_set_html_head() supposed to add code to the template $head variable... If so it may be something with my setup that is making it not work.
The 'share_sharethis' is not getting removed. What is happening is that a basic Share object can render in different ways based on what is set as the module name. So the default is 'share' but the share_sharethis module allows for another possible option of 'share_sharethis' which creates the 'share_sharethis' object that is an extension of the 'share' object. The 'share_sharethis' object then utilizes all the methods of the 'share' object that it needs and overwrites the ones it needs to change, for instance it uses the original load() method but creates it's own render().
Yes, the drupal_set_html_head() function is suppose to add data to the head of the html page. This actually needs to be changed as I recall seeing somewhere something stating that this data should actually be placed in the body and not the head. I would suggest seeing if the sharethis link shows up with the Garland theme being used, and shows up by the regular settings and not in the theme.
The problem was in fact that the gen_head() code was not being placed on the page. I ended up manually calling it on the 'share_sharethis' object in my preprocess template file and then printing it on the page.
I want to change the location of the sharthis On the page from where it is appearing. I want to remove from that location and place it on the other location. Basic question, but I'm not able to find he answer to this.
Comments
Comment #1
greenskin commentedYou can call the function 'share_popup_load' to load ShareThis object, the first parameter should be the share_id for the popup that you wish to load and then specify the optional second parameter as 'share_sharethis'. Once this is done you can render the ShareThis link by calling the render() method of the object, be sure to pass the $node object into the render method. Example code:
The best way to add things to .tpl's is to define a variable in your template.php file in a theme preprocess function, then all you need to do in your .tpl is to print that variable.
Comment #2
paradigmshifter commentedHey greenSkin, thanks for the clear explanation... I've got the js call being generated and placed in my template file. Although, I'm getting a javascript error of the SHARETHIS object not being defined...
"SHARETHIS is not defined"
I've manually included the javascript files. Is there another js call I need to make to create the SHARETHIS object? Or something else I need to do?
Thanks again
Comment #3
greenskin commentedI made a typo, the second parameter you should pass for share_popup_load should have quotes around it.
The second parameter needs to be 'share_sharethis' (no-caps) for ShareThis and 'share' for a regular Share popup. All javascript and css files get added automatically so you shouldn't have to include them yourself.
Comment #4
paradigmshifter commentedWhen running...
I'm able to see the shareThis icon and the popup begins to come up (although it's empty)... However, 'share_sharethis' still gives me the same error. When I looked at the module code for "share_popup_load" I see a switch and a case for $module='share' and default case but nothing for 'share_sharethis' ...
Comment #5
greenskin commentedThe switch statement has been removed in the latest dev version of Share. I should also note that of course Share uses drupal_add_js and drupal_add_css to add the javascript and css files so the css and javascript won't get added to the page if the code mentioned here is actually used in a .tpl file. If the code is implemented inside of a .tpl file (which should be avoided if at all possible) the theme will have to include the needed files. The best place to implement the functionality mentioned is to put it inside of the template.php file. Check http://drupal.org/node/16383 to find out how to do this.
Comment #6
paradigmshifter commentedThanks for the sticking with me on this. If the switch statement is removed or at least the "share_sharethis" portion in 2.0-alpha10 then how do you go about getting it to render? Do I have to call a function from the share_sharethis.module?
Comment #7
paradigmshifter commentedI actually believe my problem is coming from the code generated by gen_head() isn't being shown on my drupal page and therefore the sharethis.com widget doesn't exist. Is drupal_set_html_head() supposed to add code to the template $head variable... If so it may be something with my setup that is making it not work.
Comment #8
greenskin commentedThe 'share_sharethis' is not getting removed. What is happening is that a basic Share object can render in different ways based on what is set as the module name. So the default is 'share' but the share_sharethis module allows for another possible option of 'share_sharethis' which creates the 'share_sharethis' object that is an extension of the 'share' object. The 'share_sharethis' object then utilizes all the methods of the 'share' object that it needs and overwrites the ones it needs to change, for instance it uses the original load() method but creates it's own render().
Yes, the drupal_set_html_head() function is suppose to add data to the head of the html page. This actually needs to be changed as I recall seeing somewhere something stating that this data should actually be placed in the body and not the head. I would suggest seeing if the sharethis link shows up with the Garland theme being used, and shows up by the regular settings and not in the theme.
Comment #9
paradigmshifter commentedThe problem was in fact that the gen_head() code was not being placed on the page. I ended up manually calling it on the 'share_sharethis' object in my preprocess template file and then printing it on the page.
Thanks for all the thorough help!!
Comment #10
anup.tilak commentedI want to change the location of the sharthis On the page from where it is appearing. I want to remove from that location and place it on the other location. Basic question, but I'm not able to find he answer to this.
Can anyone help in this.???????
Comment #11
glewe commentedFor Drupal 7 just use this:
<?php print render($content['sharethis']); ?>Comment #12
Pallavi Gupta commentedThanks @glewe It was a great help .. :) :) I screwed my 4 hours on this simple code.