Output raw html from if statement and combining strings?
{# set test variable, to make your code work #}
{% set block = {imageWidth: 300} %}

{# the real output #}
&lt;img{{ block.imageWidth|length ? (' width="' ~ block.imageWidth~ 'px"')|raw }} /&gt;


Works for me