?
Solved

elseif in heredoc

Posted on 2016-09-06
3
Medium Priority
?
53 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

764 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