Shamoon
Shamoon

Reputation: 43531

Template data not rendering in view with ExpressJS

My view has:

{% if (process.env.NODE_ENV == 'development') %}
    <!-- Livereload script rendered -->
    <script type="text/javascript", src="http://" + req.host  + ":35729/livereload.js"></script>
{% endif %}

So I'd expect the req.host to be replaced with localhost or something. But what renders is:

<script type="text/javascript", src="http://" + req.host + ":35729/livereload.js"></script>

My express config has: app.set('view engine', 'html');

Upvotes: 0

Views: 151

Answers (1)

Paul Armstrong
Paul Armstrong

Reputation: 7156

You need to enclose your variable in the variable controls. {{ req.host }}

{% if (process.env.NODE_ENV == 'development') %}
    <!-- Livereload script rendered -->
    <script type="text/javascript", src="http://{{ req.host }}:35729/livereload.js"></script>
{% endif %}

Upvotes: 1

Related Questions