2

How to get rid of the whitespace in printed fields?

Here's my source code in node.tpl:

<div class="banner" style="background-image:url('<?php print render($content['page_banner']); ?>');">

And here's the result (whitespace before http://)

<div class="banner" style="background-image:url('  http://localhost/files/styles/1180x300/public/banners/test.jpg?itok=5LPh1ZdQ');">
</div>

Any ideas?

  • Have you tried just adding trim ? Like : <div class="banner" style="background-image:url('<?php print trim(render($content['page_banner'])); ?>'); – rtome Jan 6 '16 at 16:45
  • Excellent ! I'm glad that helped. :) – rtome Jan 6 '16 at 17:26
1

Have you tried adding a trim() ? Like :

<div class="banner" style="background-image:url('<?php print trim(render($content['page_banner'])); ?>');

It should just do the trick...

Beyond that, whatever is generating the $content['page_banner'] content is probably adding the unnecessary spaces.

| improve this answer | |

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.