Reputation: 1
<?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; ?>
Upvotes: 0
Views: 1240
Reputation: 1504
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;">
</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";
Upvotes: 0
Reputation: 11413
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.
Upvotes: 1