Zen Cart Logo
Forums / Contribution-Writing Guidelines / Difficulty displaying image in new sidebox module

Difficulty displaying image in new sidebox module

Views: 4,855

Results 1 to 5 of 5
9 Sep 2013, 12:56 PM
#1
goshawk avatar

goshawk

Zen Follower

Join Date:
Aug 2006
Location:
Kihikihi, New Zealand
Posts:
220
Plugin Contributions:
2

Difficulty displaying image in new sidebox module

Hi all,
I am trying to build a template sidebox that can be used to add several social style websites and personal blogs, that can be styled to suit different image sizes and layouts inside the sidebox.

I need to display an image that links to the site:

<a href="social_site_url/social_site_ID" target="_blank" title=""><img src="social_site.jpg" width="" height="" alt="" id="" /></a>

The image is located in templates/MY_TEMPLATE/images
My coding of both the :dontgetit<a href=""> and the :dontgetit<img src=""> are not correct.
Where did I go wrong?

tpl_social_sidebox.php:

<?php
  $content = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent" id="socialSidebox">';
  $content .= ?>'<a href="<?php FACEBOOK_URL . YOUR_FACEBOOK_NAME ?>"  target="_blank" title="<?php FACEBOOK_TITLE ?>"><img src="<?php ($template->get_template_dir(DIR_WS_TEMPLATE, $current_page_base,'images'), FACEBOOK_IMAGE_NAME ?>"  width='<?php FACEBOOK_IMAGE_WIDTH ?>' height='<?php  FACEBOOK_IMAGE_HEIGHT ?>' alt='<?php FACEBOOK_ALT ?>' id='socialImages')" /></a>';
<?php
  $content .= '</div>';
?>

Any help greatly appreciated,

Goshawk

9 Sep 2013, 2:21 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Difficulty displaying image in new sidebox module

You want to use "echo" to output the constants and data to HTML.

<?php FACEBOOK_URL . YOUR_FACEBOOK_NAME ?>

should be

<?php echo FACEBOOK_URL . YOUR_FACEBOOK_NAME ?>
9 Sep 2013, 10:33 PM
#3
goshawk avatar

goshawk

Zen Follower

Join Date:
Aug 2006
Location:
Kihikihi, New Zealand
Posts:
220
Plugin Contributions:
2

Re: Difficulty displaying image in new sidebox module

Thanks for your reply, but I still have a syntax error.

  $content .= '?><a href='<?php echo FACEBOOK_URL . YOUR_FACEBOOK_NAME ?>' target="_blank" title='<?php echo FACEBOOK_TITLE ?>'><img <?php ($template->get_template_dir(DIR_WS_TEMPLATE, $current_page_base,'images'), ?> src='<?php echo FACEBOOK_IMAGE_NAME ?>'  width='<?php echo FACEBOOK_IMAGE_WIDTH ?>' height='<?php echo FACEBOOK_IMAGE_HEIGHT ?>' alt='<?php echo FACEBOOK_ALT ?>' id="socialImages" />" /></a><?php';
10 Sep 2013, 12:03 AM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Difficulty displaying image in new sidebox module

Yes, you do. You have used single quotes for both PHP code and some HTML code, and this is confusing things. I also missed the fact that you start with PHP in $content .= , and so need to change the way you output PHP data inside the link code. ```php
$content .= '<a href="' . FACEBOOK_URL . YOUR_FACEBOOK_NAME . '" target="_blank" title="' . FACEBOOK_TITLE . '"><img src="' . ($template->get_template_dir(DIR_WS_TEMPLATE, $current_page_base,'images'), FACEBOOK_IMAGE_NAME . '" width="' . FACEBOOK_IMAGE_WIDTH . '" height="' . FACEBOOK_IMAGE_HEIGHT . '" alt="' . FACEBOOK_ALT . '" id="socialImages" /></a>';

Not guaranteeing I got every bit here...
10 Sep 2013, 12:14 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Difficulty displaying image in new sidebox module

There are two basic ways to create HTML output in a PHP file, and you can't mix them without problems.

You can use complete HTML statements outside of <?php ?> tags, with variables inserted using <?php echo $whatever ?>. This will output each line of HTML to the browser immediately as it occurs in the file.

Or you can accumulate the HTML content in a variable like $content, and output the entire thing later using <?php echo $content;?>