0
<?php if ($this->checkPosition('image')) : ?>
<?php
echo "<table class=\"remove-margin-t\"  cellpadding=\"0\" cellspacing=\"0\" width=\"97%\"  align=\"center\" border=\"0\" style=\"max-width:625px; border:1px solid;\" background=\"..\images";
?>
<?php
echo $this->renderPosition('image')
<?php
echo ".png\">";
?>
<?php endif; ?>

I am trying to figure out how to call the image properly. echo for image is called and has a specific name like 'pink','blue','green' etc. However, it depends on the position part...

This is what it is supposed to look like in html.

<table cellpadding="0" cellspacing="0" width="97%" align="center" border="0" style="max-width:625px; border:1px solid #CCC"  background="http://localhost/images/[insert color name here].png" >

Here is the original php

<?php if ($this->checkPosition('color')) : ?>
<?php echo $this->renderPosition('color'); ?>
<?php endif; ?>

Any help would be appreciated. I am sure it must be a '\' or '"' issue.

Best,

Steven

To Jared:

Do you mean like this?

<?php if ($this->checkPosition('image')) : ?>
<?php
echo "<table class=\"remove-margin-t\"  cellpadding=\"0\" cellspacing=\"0\" width=\"97%\" align=\"center\" border=\"0\" style=\"max-width:625px; border:1px solid;\" background=\"../images/";
echo $this->renderPosition('image')
echo ".png\">";
?>
<?php endif; ?>
5
  • Does putting a slash at the end of images help, background=\"../images/" Commented Aug 6, 2012 at 0:28
  • 2
    You've gone a little PHP-tag crazy there, huh? It is, it isn't, it is, it isn't, open, closed, open, closed, open again! Do one or the other (to echo or not to echo, this is the question). Commented Aug 6, 2012 at 0:30
  • even if I do this background=\"../images/"; it still is broken, :( Commented Aug 6, 2012 at 0:31
  • <?php if ($this->checkPosition('image')) : ?> <?php echo "<table class=\"remove-margin-t\" cellpadding=\"0\" cellspacing=\"0\" width=\"97%\" align=\"center\" border=\"0\" style=\"max-width:625px; border:1px solid;\" background=\"../images/"; echo $this->renderPosition('image') echo ".png\">"; ?> <?php endif; ?> Commented Aug 6, 2012 at 0:32
  • Ignore the errors, but I'd probably use a HEREDOC and a $color variable: codepad.org/akAfjKKl (If I'm not using a template technique.) Commented Aug 6, 2012 at 0:37

2 Answers 2

1

You don't need to open/close PHP tags on every line of PHP code. Your code may be rewritten this way:

<?php

if ($this->checkPosition('image')) {
    echo '<table class="remove-margin-t" cellpadding="0" cellspacing="0" width="97%"  align="center" border="0" style="max-width:625px; border:1px solid;" background="../images"' . $this->renderPosition('image') . '.png">';
}

?>

I replaced some double quotes with single quotes to avoid using backslashes everywhere.
I concatenated your text so that only one echo is used.

And I fixed a possible mistake at the end of the first echo: I replaced the blackslash by a slash, since directory separators in URLs are slashes.

Sign up to request clarification or add additional context in comments.

7 Comments

Now, no endif... Also note your quotes are still a little off.
Hi, thank you. I am looking at the code in Notepad ++ and it greys out completely after png.
@PrePCATStudent: check you are using the latest version of the code I posted in my answer (I edited several times). I am using Notepad++ too and the syntax coloring looks fine.
yeah, it's fine now...now I am trying to figure out how why all my css no longer works...thanks for the help!
Jocelyn, I edited to add curly braces (so that the gotchas associated with that style in PHP aren't transferred accidentally).
|
0

I don't know what object '$this' is, nor do I know what the method checkPosition does Also, what output 'renderPosition('color') produces.

either way, this code

<?php if ($this->checkPosition('color')) : ?>
<?php echo $this->renderPosition('color'); ?>
<?php endif; ?>

is improper, and should be written as:

<?php
if ($this->checkPosition('color')) {
     echo $this->renderPosition('color');
} 
?>

With that said, the server tags "?php" and "?" represent the beginning and end of server code. So outside of those tags is standard html markup, generally.

So, you can use html markup outside of server code as so,

<?php if ($this->checkPosition('color')) { ?>
      <div style="width:97%;text-align:center;max-width:625px;border:1px solid #CCC;background-image:url('<?php echo "http://localhost/images/" . $this->renderPosition('color') . ".png"; ?>');display:inline-block;position:relative;">
          &nbsp;
      </div>
<?php } ?>

I turned your table into a div, and used CSSstyleAttributes, instead of depreciated html attributes.

Also, I am also assuming the output of renderPosition is a filename, without the file extension.

EDIT:

localhost refers to your own computer.

You may want to use:

echo "//" . $_SERVER['SERVER_NAME'] . "/images/" . $this->renderPosition('color') . ".png";

in place of

 echo "http://localhost/images/" . $this-renderPosition('color') . ".png";

2 Comments

Hi, thanks. It is literally 'pink'. So for the top code, it will display the word 'pink' but will not display the background image as pink.png from the location...that is what I am essentially trying to do. Also, I am editing this for 'Zoo' by yootheme. So I am using their own code and editing it to do what I would like it to do. :)
in that case the code I revised should output a div tag with the inline-style attribute "background-image: url('localhost/images/ping.png')".. which will work if the file exists at that location. the file (ping.png), is it a pattern, to be repeated? what is the width and height of the image file? The html encoded space "&'nbsp;", without the apostrophe ( ' ), ensures that there is content in the div tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.