Solved

elseif in heredoc

Posted on 2016-09-06
3
49 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

688 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