Forums / Templates, Stylesheets, Page Layout / Blank Sidebox Image Won't Show

Blank Sidebox Image Won't Show

Locked

Views: 2,107

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
27 Jul 2009, 10:53 PM
#1
jsmith1611 avatar

jsmith1611

New Zenner

Join Date:
Jul 2009
Posts:
12
Plugin Contributions:
0

Blank Sidebox Image Won't Show

Hello, I am trying to place an image in my blank sidebox. All I can get to show up is the alt text no matter what I try. Here is the code from my tpl_blank_sidebox:

//$content .= '<p>' . TEXT_BLANK_SIDEBOX . '</p>';
$content .= '<ul> <li>bullet 1</li><li>bullet 2</li><li>bullet 3</li></ul>
<img src="../images/leftColImage.gif" alt="left column image" >

';

$content .= '</div>';

I have even tried placing the image in the same directory as the tpl file and changing the path. Any suggestions would be greatly appreciated. I am at my wits end. :wacko:

27 Jul 2009, 11:05 PM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Paths in Zen Cart are relative to the site's root, so your path suggests that the image is in a folder at the same level but parallel to your site's root. This seems unlikely. Where is it actually? In your main images folder, or your template's images folder?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

28 Jul 2009, 1:59 AM
#3
jsmith1611 avatar

jsmith1611

New Zenner

Join Date:
Jul 2009
Posts:
12
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

The image is in my template images folder.

28 Jul 2009, 10:48 AM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Then your image src will need to be the path to where the image is, something like includes/templates/YOUR_TEMPLATE_FOLDER/images/leftColImage.gif

It might be better, if you might ever change templates, to put it into the main images folder and use:

$content .= '<ul> <li>bullet 1</li><li>bullet 2</li><li>bullet 3</li></ul>
<img src="' . DIR_WS_IMAGES . 'leftColImage.gif" alt="left column image" >';

or better still, add it to the sidebox using css, since from your code it looks as though it has no associated behaviour or function.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 9:11 AM
#5
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

Greetings, couldn't find the Support thread for the Blank Sidebox v2 (by kuroi) so thought I'd post my question here.

It is stated that one can use PHP code within but I cannot figure out how and would like some guidance.

I have tried using:

<?php echo 'Some text here'; ?>
  • this gives a parse error
<?php echo \'Some text here\'; ?>
  • this shows commented out - does not parse

echo 'Some text here'

  • this shows all text verbatim - does not parse

Does not matter which file is used, tpl_blank_sidebox.php or blank_sidebox_defines.php

Anyone know where I am going wrong?

The learning is in the doing.

Potent Products

1 Aug 2009, 9:23 AM
#6
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Website Rob:

It is stated that one can use PHP code within but I cannot figure out how and would like some guidance.I think you're going to have a "duh" moment :wink:

Sideboxes work by loading up a variable called $content with the html that is to be output. The blank sidebox also follows this pattern. You can see this in action in the example in the previous post, and the examples in template file that comes in the mod's release pack.

So to take your first example, which I assume you are puting into the tpl_blank_sidebox.php file, you can't put php tags in, because all the file contents are already inside php tags. Instead you would simply add your content to the string of HTML that is being built up by inserting

$content .= 'Some text here';

Or better still, give it a bit of structure

$content .= '<p>Some text here</p>';

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 9:28 AM
#7
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

I understand what you are saying but I'm looking to put in PHP code, not plain text or HTML.

As stated within the module itself; tpl_blank_sidebox.php

$content .= '<p>You can include text, links, images, HTML markup and even PHP code</p>';

Can you provide an example of how PHP code would be used?

The learning is in the doing.

Potent Products

1 Aug 2009, 9:35 AM
#8
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

The example already given was PHP. A slightly more complex one would be:

$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';

Or you could use loops such as (taken from tpl_order_history.php)

  for ($i=1; $i<=sizeof($customer_orders); $i++) {
        $content .= '<li><a href="' . zen_href_link(zen_get_info_page($customer_orders[$i]['id']), 'products_id=' . $customer_orders[$i]['id']) . '">' . $customer_orders[$i]['name'] . '</a>  <a href="' . zen_href_link(basename($PHP_SELF), zen_get_all_get_params(array('action')) . 'action=cust_order&pid=' . $customer_orders[$i]['id']) . '">' . zen_image($template->get_template_dir(ICON_IMAGE_TINYCART, DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . ICON_IMAGE_TINYCART, ICON_TINYCART_ALT) . '</a></li>' . "\n" ;
  }

Any PHP really, just append the final output to the $content string.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 9:50 AM
#9
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

I just don't seem to be getting it. Almost seems like only certain types of PHP code can be used and/or the PHP code needs to be wrapped within HTML code.

This is the code I am working with but can not yet get to work correctly.

$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';

$content .= '<p>' . TEXT_SHOPPINGCART_SIDEBOX . '</p>';
$content .= '';
$content .= '
if ($_SESSION['cart']->count_contents() == 0) {
$products = $_SESSION['cart']->get_products();
echo 'Your Cart is Empty!';
}

if ($_SESSION['cart']->count_contents() > 0) {
$products = $_SESSION['cart']->get_products();
echo '' . $_SESSION['cart']->count_contents().' Item - ';
echo $currencies->format($_SESSION['cart']->show_total());
}';

$content .= '</div>';

The above code is used for the one-liner Shopping Cart display; number of items and dollar amount. Escaping any single quotes prevents parse errors but then the PHP code will not parse.

Due to the setup of the Template I am working on, it is the code the works best but needs to be in a Sidebox.

The learning is in the doing.

Potent Products

1 Aug 2009, 10:01 AM
#10
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Revised code ...

$content = '';
$content .= '<p>' . TEXT_SHOPPINGCART_SIDEBOX . '</p>';

if ($_SESSION['cart']->count_contents() == 0) {
  $content .= 'Your Cart is Empty!';
}

if ($_SESSION['cart']->count_contents() > 0) {
  $products = $_SESSION['cart']->get_products();
  $content .= $_SESSION['cart']->count_contents().' Item - ' .  $currencies->format($_SESSION['cart']->show_total());
}

$content .= '</div>';

Here's what I did and why (line numbers refer to your original code) ...

  • Reversed the 1st and 2nd lines, and removed the concate "." from the now 1st line so that any contents left over from the previous sidebox are cleared out.
  • Removed line 3, you don't want to append your processing logic to the $content string.
  • You want to append the results of that logic.
  • Removed line 6, if the count is 0, there are no products to get
  • In line 7, appended the output, instead of trying to echo it prematurely (echoing will be done later by Zen Cart).
  • Similarly lines 12 and 13 which I also cleaned up and merged (you may want to add some HTML here to to provide some structure when it's output.
  • Removed some superfluous stuff from line 14
    I haven't tried to test this, so please do post back and let me know how it goes.

The above code still retrieve the product list from the cart when there are some, but you will probably want to get rid of that too, unless you plan to take this further and expand and display them.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 10:17 AM
#11
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Oops. The following should be inserted between the first and second lines

$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";

Always need this for a 1.3 sidebox.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 10:40 AM
#12
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

Your code works a treat, kuroi... thanks.

I can see how you removed all 'echo' statements and replaced with the append: $content .=
I take it 'echo' statements will not work or is it a case a of being able to properly tweak when needed?

Reason I ask is that I tried adding the following to your code, just above and then below the closing DIV statement.

echo zen_image(DIR_WS_TEMPLATES . $template_dir . '/images/some_image.jpg','alt text goes here');

Although it worked, image was displayed, it was outside and above the Sidebox both times. Various trial & error methods could not get the image to display within the Sidebox.

Also, original module code does not use a "\n"; at the end of the opening DIV line but I guess it makes no difference?

The learning is in the doing.

Potent Products

1 Aug 2009, 10:49 AM
#13
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Blank Sidebox Image Won't Show

Sideboxes are built before the the page is rendered and their output stored until the right time to output it comes along. This means that content that is echoed will be sent to the browser, but ahead of the stuff it should be with. That's why you could see it, but not persuade it to go nicely into its box.

However, the following should achieve what you want, where you want it ...
$content .= zen_image(DIR_WS_TEMPLATES . $template_dir . '/images/some_image.jpg','alt text goes here');

The "\n" are newlines that will impact your source code only. Without them big clumps (techie term) of html tend to end up on the same line. Works just as well from a visitor's viewpoint, but can be a pain to debug if you've got a structural issue, so I tend to spread the "\n" around liberally.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

1 Aug 2009, 10:59 AM
#14
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Blank Sidebox Image Won't Show

Thanks again for the bit more information.

Using $content .= was part of my previous trial & error for including the image. Clearing, and/or wrapping with HTML tags, nothing seemed to work. Shall plug away at it though as it would be a nice feature to be able to add. Perfect example would be being able to add a Shopping Cart image and as a link, to the above code.

For now, you helped clear up the problem I was having and appreciate the help.

The learning is in the doing.

Potent Products