I am new to Drupal 8. I am building a website with Drupal 8, and it has many blocks contain images. They have an absolute path for the src attribute right now. I would like to make them dynamic base on the base URL, but there is no text format support PHP code anymore for security reason. Is there a safe way to achieve this?


You could and should do your PHP logic with template_preprocess_block. As creating a programmatic block just so you can use PHP is more work than necessary, overkill, for this use case.

Also, without any more specific info regarding make them dynamic based on base URL, this is as far as I can go.

  • Cheers man, thank you for providing that solution.
    – Siyu Qian
    Feb 3 '17 at 20:35

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.