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
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
?>
to my node.tpl.php file. nothing. it doesn't print the service links. i can get them to show up in the links, and i can get them to show up in the node (under the content), but both of these are default options. i can't get them to print where i want them to print.

am i missing a step? do i need to change something in the function?

thanks.

#1

yuriy.babenko - May 30, 2008 - 17:36

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

japanitrat - May 31, 2008 - 14:33

_phptemplate_variables(..) is no longer supported in D6.

use preprocess_callback instead, see http://drupal.org/node/132442#theme-templates for more information

#3

debonator - June 11, 2008 - 20:27

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

yuriy.babenko - June 11, 2008 - 22:05

Throw this into your template.php:

<?php
function 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

debonator - June 12, 2008 - 20:07

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

yuriy.babenko - June 12, 2008 - 20:56

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

typehost - July 26, 2008 - 11:05

Thanks for the explanation. I tried this with both phptemplate_preprocess_page and phptemplate_preprocess_node but could not get it to work.

#8

greenSkin - July 27, 2008 - 00:06

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

bjraines - November 30, 2008 - 05:41

i see how this works but what if we wanted to print each service link separately?

#10

xjessie007 - December 8, 2008 - 09:37

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

jwells - December 15, 2008 - 02:23

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

Fleshgrinder - December 18, 2008 - 01:09

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

SallySaucer - January 29, 2009 - 20:37

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

vradul - February 26, 2009 - 00:21
Version:6.x-1.0» 5.x-1.1
Category:support request» feature request

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

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;

In your themes node.tpl.php insert <?php print $service_links; ?> as shown here

  <?php if ($submitted): ?>
    <span class="submitted">
      <?php print t('by <strong>!username</strong> | !date', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?><?php print $service_links; ?>
  <?php endif; ?>

#15

cookiesunshinex - July 22, 2009 - 03:06

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.

Throw this into your template.php:

<?php
function 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.

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?

 
 

Drupal is a registered trademark of Dries Buytaert.