Add if Condition in HEREDOC notation in PHP

I am using HEREDOC Notation. I am facing issues in using If condition in it.
Here is my code

$res = <<< HTML2
<div class="row">
 <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
     <div class="hero-slider" id="hero-slider">
         <ul>
             <li>
                 <div class="media">
                     <figure> <img  src="{$upload_base_path}misc/uploads_/{$image}" alt="">
                         <figcaption>
                             <h1 class="bgcolor">ABC Text</h1>
                             <br/>
                             <p class="text bgcolor">This is second text</p>
                             <br/>
                             <button class="btn bgcolor">Third Text</button>                                  
                                <img src="{$upload_base_path}misc/uploadsimage/{$graphic_image}">


                         </figcaption>
                     </figure>

                 </div>
             </li>
             </ul>
         </div>
     </div>
 </div>
</div>
HTML2;

Open in new window


Actually I want to apply condition before the <img tag>. Need help for that.
Shano KhanSoftware EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
Just generate the content before the heredoc starts. For example, if you want the image to only show up under a certain condition...

// Determine whether to show the image or not
$conditional_image = "<img src="{$upload_base_path}misc/uploadsimage/{$graphic_image}">";
if(show_image_condition == false)
{
  $conditional_image = "";
}

// Build the content
$res = <<< HTML2
<div class="row">  
...
<br/>
                             <button class="btn bgcolor">Third Text</button>                                  
                                {$conditional_image}

                         </figcaption>
...
HTML2;

Open in new window


Or alternatively, you can stop the heredoc and resume it:


// Build the content
$res = <<< HTML2
<div class="row">  
...
<br/>
                             <button class="btn bgcolor">Third Text</button>                                  
HTML2;

// Conditional image
if(show_image_condition)
{
  $res .= "<img src="{$upload_base_path}misc/uploadsimage/{$graphic_image}">";
}

// Resume
$res = <<< HTML2

                         </figcaption>
...
HTML2;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Can you show us what you want to do - put the if in the HEREDOC to show how you want the logic to work and we can then see what the best approach is.
0
Shano KhanSoftware EngineerAuthor Commented:
thanks for this
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.