Solved

elseif in heredoc

Posted on 2016-09-06
3
18 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
  • 2
3 Comments
 
LVL 108

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 108

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now