Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I have a full-HTML block and I want to put a link to a file into it that varies with the sitepath. I saw somewhere something about putting public:// instead of http:// to route to sites/default/files, but it doesn't seem to work from block content at least (is that only in php?)

So I have a block with <img src="public://img/screenshot.png"/> in the content and nothing is happening. Any ideas how to make this work? I don't to use image module or anything like that yet.. just a link to a file.

share|improve this question

1 Answer

up vote 1 down vote accepted

You'll need to use file_create_url() and the 'PHP code' format (comes with the core 'PHP filter' module) for this to work:

<img src="<?php print file_create_url('public://img/screenshot.png'); ?>"/>

If possible I would suggest adding it inside the block's template file instead though.

share|improve this answer
so there's no way without having PHP enabled? :/ – Damon May 12 '12 at 21:46
Well, HTML code is static so you can't use it to create a dynamic link. Like I mentioned you could maybe add this code snippet directly inside the block template file though. If the sites have a similar path structure then you could use a relative url like '/sites/default/files/img/screenshot.png' also. – Dooshta May 12 '12 at 22:58
I know html code is static, but a lot of systems (like wordpress) have shortcodes so that you can do this sort of thing without having to turn on PHP scripting for a content area (which is potentially dangerous) – Damon May 14 '12 at 12:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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