Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert class if true

How do I insert a class with php if something is true? Here's my best guess so far:

<div class="<?php
  if($this->step==2){
    somehow set the name of the class
  } ?>">
like image 210
Heather Avatar asked Aug 16 '13 02:08

Heather


1 Answers

You're close; what you can do is echo the class with PHP.

<!-- Either try this... -->
<div class="<?php if($this->step === 2) { echo 'twostep'; } ?>"></div>

<!-- ...or this -->
<div class="<?=$this->step === 2 ? 'twostep' : 'notwostep'?>"></div>
like image 182
Chris Forrence Avatar answered Sep 28 '22 00:09

Chris Forrence