Is this possible? I need to build a path for an IMG in this block I have here:

<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/block_*****_image.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />
<img src="<?php print $base_path; ?>/<?php print $directory; ?>/images/user_default_bw.gif" alt="" />

$base_path and $directory aren't outputting anything, even though they work fine when used in block.tpl.php.

How can I use these variable to make img src paths in the content of a block? The input format IS set to PHP code, so that's not the problem.

Comments

advosuzi’s picture

here's what i use...
if the image is inside your theme directory you can use:

<img src="<?php print path_to_theme() ?>/images/block_*****_image.gif" alt="" />

or if it's in a dir outside drupal you can use a normal server path:

<img src="/images/block_*****_image.gif" alt="" />

jerseycheese’s picture

thanks.... used your path_to_theme() solution and it printed the path just great.

Only one big problem... this works fine if on the home page of the site, but once we're in say www.mysite.com/inside the path is no longer accurate:

Only local images are allowed.

advosuzi’s picture

if you add a leading slash it should catch the path:

<img src="/<?php print path_to_theme() ?>/images/block_*****_image.gif" alt="" />

hth!

jerseycheese’s picture

sure did.

that's basic html right there (in regards to the leading slash) and I've been doing this 10+ years. how humbling to not realize something so simple! thanks...