I've added a block called 'Course Information', configured the block to display on a particular group of pages (courses/full-time/*). This works fine, but I don't know to configure Drupal to display a different icon for each of the pages.

At present, the block contains:

<img alt="An icon symbol" src="/sites/default/files/images/icon-1.png" />

This will display the same image on each page that the block is used. How would I go about having a dynamic filename inserted, like icon-2.png, icon-3.png, icon-n.png?


If this is being displayed on nodes you can add an imagefield to the content type and set its display settings to excluded. Then make a views block that displays the image field, using a default argument of the current node.

| improve this answer | |
  • Jody, thanks for your help. I added a field to the page content type called 'course_icon' and excluded the field from display, but I'm having trouble implementing a working view to display it. Any idea where I'm going wrong? Here's a copy of the view: pastebin.com/WVmQ5sai – unpossible May 4 '11 at 15:33
  • 1
    It looks like you're using a relationship to use image module, but then you're also using an imagefield field. You can likely remove the relationship. But the real problem is your argument. Your argument should be node:nid, and under 'action to take if argument is not present' you choose 'provide default argument', 'node id from url'. – Jody May 4 '11 at 21:15
  • Thanks for your help - I shall investigate your solution. – unpossible May 23 '11 at 8:44

You can use PHP-code inside your block, and use the arg() function to solve it like

 print '<img alt="An icon symbol" src="/sites/default/files/images/icon-' . arg(2) . '.png" />'

This depends on the * behind full-time. It would be better to use an extra function with a mapping (* => int), and validation inside your theme or a module.

| improve this answer | |
  • Thanks for your help. Where should the above code be placed? Can you provide step-by-step instructions to implement this? In what respect does this solution depend on what's behind the courses/full-time/*? The content type of these nodes are all pages. – unpossible Apr 30 '11 at 10:51
  • You can change the input format of the block containing the img to "PHP code". The arg() function returns parts of the url. So the output depends on your aliases. From api.drupal.org: When viewing a page at the path "admin/content/types", for example, arg(0) would return "admin", arg(1) would return "content", and arg(2) would return "types". – nonsenz Apr 30 '11 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.