Search code examples
phppugpugjs

Trying to embed PHP within PUGs property values


What I am trying to do (using gulp-pug, that uses pugjs):

<?='test!'?>
input(type='hidden', name="!{'<?=CMS::cmsQueryParam?>'}", value='loginForm')

and what ever I could find on the pug interpolation page, but it always gives me something like this:

test!
<input type="hidden" name="!{'&lt;?=CMS::cmsQueryParam?&gt;'}" value="loginForm">

Same happens here:

input(type='text', name='user', placeholder='Username', autofocus='', value="<?=$_REQUEST['user']?>")

.. the will be converted to html entities. I have no clue how to prevent this.

Any ideas? Know of any posts, this could be a duplicate from?


Solution

  • Buffered code can be unescaped by starting with !=. e.g.

    != "<?='test!'?>"
    

    Values for tag/mixin arguments can be unescaped by assigning with != instead of =. e.g.

    input(type='hidden', name!="<?=CMS::cmsQueryParam?>", value='loginForm')
    
    input(type='text', name='user', placeholder='Username', autofocus='', value!="<?=$_REQUEST['user']?>")