Solved

elseif in heredoc

Posted on 2016-09-06
3
45 Views
Last Modified: 2016-10-08
I have just been introduced to the heredoc method and am getting into it slowly.

I figured I could use conditional statements inside the heredoc syntax but Im running into some roadblocks - (mainly my lack of knowledge)

What Im trying to do is create a hr from an array - I can get the color and the style but when it comes to showing the result, I'm falling short.

If I run this by itself it works fine - it uses a checkbox called dashed_dashed_use and if its checked it runs this, and all is well - however. Im trying to use a ifelse statement inside to simply show a
if the checkbox is not "checked".
   // START HEREDOC OUTPUT STRING
     $output = <<< START

   START;
    // IF Yes Box HAS CONTENT - ADD TO OUTPUT
    // ELSE IGNORE
    if (!empty($dashed_dashed_use)) {
      $output .= <<< DD1
        <hr style="border: 2px dashed; color:{$dashed_dashed};" data-dashed_dashed="{$dashed_dashed}">
    DD1;
    }

    // ADD CLOSING TAGS TO OUTPUT
       $output .= <<< OUTPUT_FINAL
     OUTPUT_FINAL;
    return $output;
    }

Open in new window

I cant just have a hr after the START as it will always show. So I need it so that it's a regular hr unless DD1 has been activated by the checkbox - (there are more varieties of the same, but I figured I would be able to replicate a single working version and just change the names of the $ fields.

Is this pretty straightforward, or do I need to code copies for every instance of hr I have.
0
Comment
Question by:Daryl Isaacs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points (awarded by participants)
ID: 41787123
use conditional statements inside the heredoc
Nope, doesn't work that way.  HEREDOC is just a string definition and has no conditional aspects at all.  A good way to handle the conditions is to set the variables outside the HEREDOC and then use the variables inside the HEREDOC to construct the string.
1
 

Author Comment

by:Daryl Isaacs
ID: 41787133
OK ill give it a whirl
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41834879
HEREDOC does not include conditional statements, only variable substitution.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question