How to put the if statement in HTML
FrankGomezMonta (0)

I am using the Chrome browser and how do I put in the 'if' statement in HTML?

You are viewing a single comment. View All
eankeen (997)


yeah, so nearly all html markup you write will automatically get rendered and displayed on the page, so there really isnt anything like an 'if statement in HTML'

if you want a more dynamic page, youre gonna have to use javascript (or css, depending on what you want to do).

i think you may be looking for something along the lines of a 'templating engine'. some examples of implementations include handlebars or mustache. it would look something like this:

<div class="entry">
  {{#if author}}
    <h1>{{firstName}} {{lastName}}</h1>

however, none of this syntax is valid html, so you cant just use this as-is. you would have to use some templating engine library (like handlebars or mustache, that i previously mentioned)

i would lookup 'client side templating engines' using some search engine to get more information. you can also use them server side with something like nodejs, but that requires a bit more setup.

hope i could help :)