service link positioning
debonator - May 12, 2008 - 06:58
| Project: | Service links |
| Version: | 5.x-1.1 |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
i'm trying to print the service links at the top of the page, underneath the title. i found this code in the example template.php file:
<?php
/**
* @file
* Example template.php for service_links.module
* Use <?php print $service_links ?> to insert links in your node.tpl.php or you page.tpl.php file.
*/
function _phptemplate_variables($hook, $vars) {
switch($hook) {
case 'node':
case 'page':
if (module_exists('service_links')) {
$vars['service_links'] = theme('links', service_links_render($vars['node'], TRUE));
}
break;
}
return $vars;
}i copied the function into my template's template.php file, and then added
<?php
print $service_links
?>am i missing a step? do i need to change something in the function?
thanks.

#1
I'm not sure what's wrong with your solution, but here's another way to solve your problem:
- create a new region "content top"; this is done by modifying the theme's .info file - http://drupal.org/node/171224
- go to blocks administration and move the service links block to the content top region
- modify page.tpl.php to print the content top variable above the $content variable. For example, if you added "regions[content_top] = Content Top" to your themes regions, you would use "print $content_top;"
#2
_phptemplate_variables(..) is no longer supported in D6.
use preprocess_callback instead, see http://drupal.org/node/132442#theme-templates for more information
#3
ok, i'm lost. how do i use the preprocess_callback function? i'm a newbie.
this is what i have, and it's definitely not working:
function _phptemplate_preprocess_callback($hook, $vars) {switch($hook) {
case 'node':
case 'page':
if (module_exists('service_links')) {
$vars['service_links'] = theme('links', service_links_render($vars['node'], TRUE));
}
break;
}
return $vars;
}
#4
Throw this into your template.php:
<?phpfunction phptemplate_preprocess_node(&$vars)
{
if(module_exists('service_links')) {
$vars['service_links'] = theme('links', service_links_render($vars['node'], TRUE));
}
}
?>
This will make a variable called $service_links available to your node template files (ex. node.tpl.php).
If you want the links to only appear once at the top of the page, then you need to use phptemplate_preprocess_page() instead.
#5
one last question: why do some examples show an underscore before phptemplate (_phptemplate) and some do not? i'm assuming the underscore is unnecessary.
thanks for your help.
#6
In general, Drupal functions beginning with an underscore are "internal/helper" functions. Basically, not hooks/theme over rides, or anything like that.
I'm not 100% sure of why some phptemplate functions are also prefixed with an underscore. This may be a difference between how phptemplate is setup in Drupal 5 and in Drupal 6... If there's an example, go with what's in the example :)
#7
Thanks for the explanation. I tried this with both phptemplate_preprocess_page and phptemplate_preprocess_node but could not get it to work.
#8
You will need to implement the hook_nodeapi() function in a custom module and change the weight of the Service Links to a negative number, do this in the 'view' op.
#9
i see how this works but what if we wanted to print each service link separately?
#10
Here is an alternative way.
There are two functions in service_links.module.
The theme_service_links_node_format() is responsible for theming the output when it is appended to the node.
The theme_service_links_block_format() function themes the content if you display it as a block.
hook_block() is where the output is passed to Drupal.
For some reason, if you enable block display, service links gets displayed at both places - appended to the node and in the sidebar block too. So, if you want to display the service links as a block but not in the sidebar but let's say at the top of the post (and you want to turn off displaying service links at the end of a node too), you need to modify these functions here a little.
Uncomment everything from inside of theme_service_links_node_format. This will stop displaying service links at the end of a node.
Because theme_service_links_block_format displays the service links as UL-LI by default which is ok for sidebar block but not very nice for a top/bottom content block, you need to modify theme_service_links_block_format. I probably did not do it the best way, but I think it was the easiest way. I used the strip_tags($a, 'div a img') function to just strip all but a, div, img HTML tags from the already themed output.
Now you just enable your block and position it to content top or whereever you like. Works fine.
Note, here are other Drupal thread related to the same or similar problem:
http://drupal.org/node/257361
http://drupal.org/node/288612
http://drupal.org/node/214939
__________________
Drupal cache clean up - cache_clear_all()
How to delete or clear Drupal cache tables?
#11
Thank you for your post. I didn't notice there was a block avaiable - so thanks.
I'm using a Theme with content bottom, so it is very easy to apply.
However, I would like the links inline
.service-links li {display: inline;
}
above didn't work, is there another way?
#12
Because your CSS is overwritten by the system.css style, use this:
.block .service-links .item-list ul li {display:inline;
}
Only your service-links items will be displayed inline, it won't affect anything else.
Kindest regards
Fleshgrinder
#13
In service_links.module @ line 204 -> function service_links_nodeapi(...
find code: '#weight' => 10 (appears 4 times)
change to -50 or whatever, as long as it's lighter that the content.
Not sure how to implement in template.php
#14
This will work for Drupal 5.
You'll have to work on CSS positioning yourself, but this will put service links at the top, left aligned, under the author name, as well as in the links if you want it in both places. You can disabled it in the links section if it looks too busy, and this will still display it at the top.
In your themes template.php:
Insert the following immediately after function _phptemplate_variables($hook, $vars) { to make the $service_links variable available to your node tpl files
In your themes node.tpl.php insert <?php print $service_links; ?> as shown here
#15
In service_links.module @ line 204 -> function service_links_nodeapi(...
find code: '#weight' => 10 (appears 4 times)
change to -50 or whatever, as long as it's lighter that the content.
Not sure how to implement in template.php
This worked for me, but isn't my preferred option because the next time I update the module, I have to remember to make this modification.
This need to be updated in the Drupal 6 version of template.php in the servicelinks module directory. It is currently wrong.
Also, this creates two different service links bars on all my nodes. If I place this in the theme, should I disable service links for nodes in the admin panel?