Hi all, I need to alter some node links, in the specific I'd like some icon near comment link. Right now I'm doing it using the hook, link_alter but since it's basically something related to the theme, I'd like to do it within the theme. I'm trying with template_preprocess_block but it does not seems ti work. Code looks briefly like: $node = $vars['node']; $node->links['comment_comments']['title'] = '<img src="foo"/>'; .. $vars['links'] = $node->links; I suppose this is not the correct way, any hints? regards
Do you want to replace the text with a link or just add an image next to the link text? You could use CSS to define a background-image and then push the text to the left with a margin. This way you can show an imagine to the general public viewing your site but also hide it from other types of non-visual media browsers. Unless I'm misunderstanding what you're trying to accomplish. Todd On 18 November 2010 13:30, Salvatore De Paolis <iwkse@gmx.com> wrote:
Hi all,
I need to alter some node links, in the specific I'd like some icon near comment link. Right now I'm doing it using the hook, link_alter but since it's basically something related to the theme, I'd like to do it within the theme.
I'm trying with template_preprocess_block but it does not seems ti work.
Code looks briefly like:
$node = $vars['node']; $node->links['comment_comments']['title'] = '<img src="foo"/>'; .. $vars['links'] = $node->links;
I suppose this is not the correct way, any hints?
regards
On Thu, 18 Nov 2010 13:39:43 -0500 Todd <todd@savagevenus.net> wrote:
Do you want to replace the text with a link or just add an image next to the link text?
That's it, in some cases i just want a link with only the picture on it and the text visible in the tooltip. I was achieving this using the link_alter before, i was wondering if i can do the same also in the theme.
You can do it in the CSS. Something like: .infoAndActions ul li.comment_add, .infoAndActions li.comment_comments { background: url(/sites/all/themes/forresterblogs/images/infoAndActions_commentCount.gif) no-repeat left 8px; padding-left: 29px; margin-left: .3em; } Nancy Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr. ________________________________ From: Salvatore De Paolis <iwkse@gmx.com> To: development@drupal.org Sent: Thu, November 18, 2010 1:30:30 PM Subject: [development] Altering links Hi all, I need to alter some node links, in the specific I'd like some icon near comment link. Right now I'm doing it using the hook, link_alter but since it's basically something related to the theme, I'd like to do it within the theme. I'm trying with template_preprocess_block but it does not seems ti work. Code looks briefly like: $node = $vars['node']; $node->links['comment_comments']['title'] = '<img src="foo"/>'; .. $vars['links'] = $node->links; I suppose this is not the correct way, any hints? regards
On Thu, 18 Nov 2010 10:57:26 -0800 (PST) nan wich <nan_wich@bellsouth.net> wrote: Hi,
You can do it in the CSS. Something like: .infoAndActions ul li.comment_add, .infoAndActions li.comment_comments { background: url(/sites/all/themes/forresterblogs/images/infoAndActions_commentCount.gif) no-repeat left 8px; padding-left: 29px; margin-left: .3em; }
Nancy
Yes thanks I could do this way, but I need more control over it. For example when no comments, I'd only like to show the icon and the text in the tooltip.
$vars['links'] is generated by theme_links(). Look at template_preprocess_node() in includes/theme.inc: http://drupalcode.org/viewvc/drupal/drupal/includes/theme.inc?revision=1.415... $variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : ''; Unless you absolutely consider the icons to be content and not styling, CSS is the way to go instead of <img> tags. Different CSS classes may be applied via theme_links() to indicate whether comments exist. CSS also allows for the use of sprites. On Thu, Nov 18, 2010 at 12:27 PM, Salvatore De Paolis <iwkse@gmx.com> wrote:
On Thu, 18 Nov 2010 10:57:26 -0800 (PST) nan wich <nan_wich@bellsouth.net> wrote:
Hi,
You can do it in the CSS. Something like: .infoAndActions ul li.comment_add, .infoAndActions li.comment_comments { background:
url(/sites/all/themes/forresterblogs/images/infoAndActions_commentCount.gif)
no-repeat left 8px; padding-left: 29px; margin-left: .3em; }
Nancy
Yes thanks I could do this way, but I need more control over it. For example when no comments, I'd only like to show the icon and the text in the tooltip.
On Thu, 18 Nov 2010 12:31:23 -0700 Carl Wiedemann <carl.wiedemann@gmail.com> wrote:
$vars['links'] is generated by theme_links(). Look at template_preprocess_node() in includes/theme.inc: http://drupalcode.org/viewvc/drupal/drupal/includes/theme.inc?revision=1.415...
$variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
Yes i misunderstood it, i thought it was some kind of overriding
Unless you absolutely consider the icons to be content and not styling, CSS is the way to go instead of <img> tags. Different CSS classes may be applied via theme_links() to indicate whether comments exist. CSS also allows for the use of sprites.
As i said in the previous comment, in some cases, i'd want only the icon which i suppose i can't achieve only with CSS.
You could achieve it with both CSS and preprocess by doing something like this: In your template.php file, mytheme_preprocess_node(): // START $node = $vars['node']; if (!empty($node->links['comment_comments'])) { // Class depending on node comment count. if (!empty($node->comment_count)) { $myclass = 'has-comments'; } else { $myclass = 'no-comments'; } // Add to particular link class. if (empty($node->links['comment_comments']['attributes']['class'])) { $node->links['comment_comments']['attributes']['class'] = $myclass; } else { $node->links['comment_comments']['attributes']['class'] .= ' ' . $myclass; } // Reformat all links $vars['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : ''; } // END In your theme's css file /* START */ .has-comments { backgorund-image: url(./images/some-image.png); background-repeat: none; padding-left: 2em; } .no-comments { background-image: none; padding-left: 0; } /* END */ On Thu, Nov 18, 2010 at 1:01 PM, Salvatore De Paolis <iwkse@gmx.com> wrote:
On Thu, 18 Nov 2010 12:31:23 -0700 Carl Wiedemann <carl.wiedemann@gmail.com> wrote:
$vars['links'] is generated by theme_links(). Look at template_preprocess_node() in includes/theme.inc:
http://drupalcode.org/viewvc/drupal/drupal/includes/theme.inc?revision=1.415...
$variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : '';
Yes i misunderstood it, i thought it was some kind of overriding
Unless you absolutely consider the icons to be content and not styling, CSS is the way to go instead of <img> tags. Different CSS classes may be applied via theme_links() to indicate whether comments exist. CSS also allows for the use of sprites.
As i said in the previous comment, in some cases, i'd want only the icon which i suppose i can't achieve only with CSS.
On Thu, 18 Nov 2010 13:21:48 -0700 Carl Wiedemann <carl.wiedemann@gmail.com> wrote:
// Add to particular link class. if (empty($node->links['comment_comments']['attributes']['class'])) { $node->links['comment_comments']['attributes']['class'] = $myclass; } else { $node->links['comment_comments']['attributes']['class'] .= ' ' . $myclass; }
// Reformat all links $vars['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : ''; } // END
Maybe I am misunderstanding it or/and I did not explain good. Is not it supposed to show the text "no comments" when there are not comments and instead when some comments it shows the text together with the icon? I want something different, when no comments, it shows no text but only the icon. When some comments, it shows both text and icons.
Preprocess functions will allow you to change the text of the link as well. Call devel module's dpm() function to inspect the links array in the preprocess function http://drupalcontrib.org/api/function/dpm. Change the 'title' attribute of the link depending on $node->comment_count. dpm() output: http://imagebin.ca/view/WdTNRdD.html On Thu, Nov 18, 2010 at 2:10 PM, Salvatore De Paolis <iwkse@gmx.com> wrote:
On Thu, 18 Nov 2010 13:21:48 -0700 Carl Wiedemann <carl.wiedemann@gmail.com> wrote:
// Add to particular link class. if (empty($node->links['comment_comments']['attributes']['class'])) { $node->links['comment_comments']['attributes']['class'] = $myclass; } else { $node->links['comment_comments']['attributes']['class'] .= ' ' . $myclass; }
// Reformat all links $vars['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : ''; } // END
Maybe I am misunderstanding it or/and I did not explain good. Is not it supposed to show the text "no comments" when there are not comments and instead when some comments it shows the text together with the icon? I want something different, when no comments, it shows no text but only the icon. When some comments, it shows both text and icons.
On Thu, 18 Nov 2010 15:18:16 -0700 Carl Wiedemann <carl.wiedemann@gmail.com> wrote:
Preprocess functions will allow you to change the text of the link as well. Call devel module's dpm() function to inspect the links array in the preprocess function http://drupalcontrib.org/api/function/dpm. Change the 'title' attribute of the link depending on $node->comment_count.
dpm() output: http://imagebin.ca/view/WdTNRdD.html
Thanks a lot Carl, it is what i was looking for!
participants (4)
-
Carl Wiedemann -
nan wich -
Salvatore De Paolis -
Todd