1

Hi all, iam trying to set image here in a module .The image is in the same module folder. but iam not able to get the image path

<td><img src="projectsetup.jpg "  width="42" height="42"></td>

This is the error which iam getting ..cleary states no path

enter image description here

How to get a relative path in module to display images?

2 Answers 2

0

Drupal has ways to get the relative path from document root but not for individual module/theme folder.

You can get the path to current module or theme using path_to_theme

<img src="/<?php echo path_to_theme() ?>/images/projectsetup.jpg"/>

path_to_theme from the documentation

Returns the path to the current themed element.

It can point to the active theme or the module handling a themed implementation. For example, when invoked within the scope of a theming call it will depend on where the theming function is handled. If implemented from a module, it will point to the module. If implemented from the active theme, it will point to the active theme. When called outside the scope of a theming call, it will always point to the active theme.

2
  • @GiorgoskK: Madhu is talking about the module, not the theme. path_to_theme will give the path to theme folder, not the module. Commented Mar 12, 2018 at 6:53
  • @jeetendra My answer is still correct was just not answered properly so i revised ... so I don't understand the reason for downvoting
    – GiorgosK
    Commented Mar 12, 2018 at 7:10
0

Try this code.

$path = drupal_get_path('module', 'myModule') . 'image/projectsetup.jpg';

now set src = '$path' into your .module file where you set image src.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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