Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Question after following the Custom Sidebox Tutorial in the wiki

Question after following the Custom Sidebox Tutorial in the wiki

Views: 1,798

Results 1 to 17 of 17
25 Apr 2013, 3:28 PM
#1
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Question after following the Custom Sidebox Tutorial in the wiki

I found this tutorial, followed it, works pretty good: https://www.zen-cart.com/wiki/index.php/Making_a_Custom_Sidebox, but there is a gotcha or two.

  1. The tutorial is great for creating a sidebox that mimics the theme's sideboxes, same style header box, etc. But if I don't want to display the header box, just whatever content I make up, what do I disable or change to make it go away. Why, I'm making a custom social header to house various social media buttons - and it really looks odd and takes up extra space to have a box header called "Social something".

  2. I was logged into the server doing my edits. After I created the "~/www/includes/modules/sideboxes/$TEMPLATE/social_sidebox.php file I exited v.i. and went to the admin panel and all was good. Then I went back into v.i. which creates a swap file and went back to the Tools / Layout box Controller - and it recognized the ".swp" file as something and is trying to tell me to configure it. Exiting V.i. and removing the .swp file. If this involves a db change I can handle the SQL.

Attachment 12398

25 Apr 2013, 3:53 PM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Question after following the Custom Sidebox Tutorial in the wiki

If it were me, I would just use the Blank Sidebox plugin. You can turn specific sidebox headers off in the stylesheet using something like #blankSideboxHeading {display: none;}

25 Apr 2013, 4:32 PM
#3
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

I'll consider blank sidebox for future needs, however here I would really like to get this working and fix the Error caused by the swap file.

Does blank sidebox allow for PHP coding?

Suggestion: There are a great bunch of extensions out there, however they're not always that easy to find. If you know the category it minimizes the effort. If not, there can be a lot of hopping around. Has anyone considered taking the whole batch and dropping them into a single page with the categories as headers (and no pagination). It may be a little slow-loading but it is easier than hopping around through each category.

25 Apr 2013, 6:20 PM
#4
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

This has taken a downward twist. I restored the database and filesystem to get rid of the error. Works fine. So I repeate the process avoiding any v.i. conflicts. Now if I go to the public page the content is displaying out of order, above the header (backwards).

The code:

social_media.php:

<?php
 $show_social_media = true;
 if ($show_social_media == true){
   require($template->get_template_dir('tpl_social_media.php',DIR_WS_TEMPLATE,
   $current_page_base,'sideboxes'). '/tpl_social_media.php');
   $title =  BOX_HEADING_SOCIAL_MEDIA;
   $left_corner = false;
   $right_corner = false;
   $right_arrow = false;
   require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE,
   $current_page_base,'common') . '/' . $column_box_default);
 }
?>

social_media_defines.php:

<?php
  define('BOX_HEADING_SOCIAL_MEDIA', 'Social Media');
?>

tpl_social_media.php:

Whatever ...

Anything obvoius?

25 Apr 2013, 7:20 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Question after following the Custom Sidebox Tutorial in the wiki

Have you adjusted your sort orders to fix the order in which it displays? Negative numbers are permitted, and do help give greater control.

Also, you didn't state which ZC version you're using.

25 Apr 2013, 10:21 PM
#6
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

ZC151

Yes I tried adjusting the sort order. Makes no difference.

This is so bizarre because the first one I created looked good with the HEADER above the text. Getting rid of the header would still solve the original problem and now this one.

Attachment 12405

As you can see the text, Facebook, is hanging aboe the box header "SOCIAL MEDIA".

25 Apr 2013, 11:14 PM
#7
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Question after following the Custom Sidebox Tutorial in the wiki

Screenshots aren't really helpful. A link to the site might let us spot something.

26 Apr 2013, 3:24 AM
#8
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

The site via IP address: http://174.121.22.85/~dgodod/

This is a live site so I don't want to leave the break up for an extended period. I enabled it and gave it a high number so that it should be at the very bottom of the left column. It is getting stranger. It should be living under the Information box which I renamed Shop Policies. The new twist - The shop policies ordered listed is being duplicated below Social Media. Here is the relevant HTML code:

<!--// bof: information //-->
        <div class="box" id="information" style="width:230px;">


										
											<div class="box-head">
												Shop Policies											</div>
			
											<div class="box-body">
												<div id="informationContent" class="sideBoxContent">
<ul style="margin: 0; padding: 0; list-style-type: none;">
<li><a href="http://www.dgoaccess.net/index.php?main_page=shippinginfo">Shipping & Returns</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=privacy">Privacy Policy</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=contact_us">Contact Us</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=site_map">Site Map</a></li>
</ul>
</div>											</div> 
			

            
        </div>
<!--// eof: information //-->
<h3>Facebook</h3>
<!--// bof: socialmediasidebox //-->
        <div class="box" id="socialmediasidebox" style="width:230px;">


										
											<div class="box-head">
												Social Media											</div>
			
											<div class="box-body">
												<div id="informationContent" class="sideBoxContent">
<ul style="margin: 0; padding: 0; list-style-type: none;">
<li><a href="http://www.dgoaccess.net/index.php?main_page=shippinginfo">Shipping & Returns</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=privacy">Privacy Policy</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=contact_us">Contact Us</a></li>
<li><a href="http://www.dgoaccess.net/index.php?main_page=site_map">Site Map</a></li>
</ul>
</div>											</div> 
			

            
        </div>
<!--// eof: socialmediasidebox //-->
					</div>
26 Apr 2013, 9:12 PM
#9
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

  1. I took a look at "Blank Sidebox". It does not appear to work using PHP code. I tested it with PHP, maybe it is good with JavaScript.

  2. For the current problem it looks weird and I don't want to leave it up there on the site for an extended period.

  3. Door #3 for PHP code - not all the zencart sidebox modules get used for all sites. I scanned the list; this site will never need any of the music-related boxes. I took a look at music genres. It's easy enough to modify both the header and contents. Very simply:

I left the original $content and added a new line: $content = "whatever code ..."; Then I modify the language file for the header. This is not the right way to solve the problem, but it works in the interim until this is understood and fixed.

26 Apr 2013, 9:30 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Question after following the Custom Sidebox Tutorial in the wiki

The same principle applies for all sideboxes. Use your PHP code to generate the desired output HTML, and stuff that output into the $content variable. It will then be output in the sidebox, where the sidebox is positioned.

27 Apr 2013, 1:07 PM
#11
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

Yes, Sensei, I understand this (wakarimasu), as a workaround and I can live with this, however, that doesn't solve the problem of why the sidebox tutorial isn't working properly on the site, why it is 1) Outputting content above the header and 2) Forcing output from the box immediately preceding the module to duplicate. Over ...

27 Apr 2013, 8:41 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Question after following the Custom Sidebox Tutorial in the wiki

dmitrikoniahin:

that doesn't solve the problem of why the sidebox tutorial isn't working properly on the site
Dunno. I've not used that tutorial. You're probably not resetting values properly between outputs or something. Without having a complete copy of all the code you've changed/created to do this, it's very hard to tell you where you went wrong.
Usually a good place to start is by comparing what you've done against existing sidebox code and see what's missed or added wrong. That's where I'd have to start if I had the files from your code anyway.

28 Apr 2013, 6:56 PM
#13
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

Aside from the fact that I changed the contents of the text from "whatever" to "Facebook" to make it look less stupid while it's published, I included the 3 mods per the instructions early on in this thread.

I don't know anything about resetting variables; that was not in the instructions.

28 Apr 2013, 7:53 PM
#14
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Question after following the Custom Sidebox Tutorial in the wiki

I'm trying to indulge you by adding the content you posted onto my own site to see what could possibly be going wrong.
But unsurprisingly it all breaks when I only put the literal text "Whatever..." into tpl_social_media.php ...

dmitrikoniahin:

The code:

social_media.php:

<?php $show_social_media = true; if ($show_social_media == true){ require($template->get_template_dir('tpl_social_media.php',DIR_WS_TEMPLATE, $current_page_base,'sideboxes'). '/tpl_social_media.php'); $title = BOX_HEADING_SOCIAL_MEDIA; $left_corner = false; $right_corner = false; $right_arrow = false; require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . $column_box_default); } ?>
> 
> social_media_defines.php:
> 
> ```
<?php
  define('BOX_HEADING_SOCIAL_MEDIA', 'Social Media');
?>

tpl_social_media.php:

Whatever ...

> 
> Anything obvoius?

Instead, putting the following into the tpl_social_media.php file works fine:```
<?php
    $content = ''; // this resets the $content variable so it doesn't repeat the content from the previous sidebox
    $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent centeredContent">';
    $content .= 'Whatever';
    $content .= '</div>';
```Substituting the word "Facebook" in place of "Whatever" works fine too.

The key is that your raw HTML needs to be placed inside the $content  variable. And that also means all your quotes need to be properly  escaped if your HTML contains any.

ie: $content = 'if it contains quotes they\'ve gotta be escaped like the one in the middle of this line is';

Basic PHP syntax (well any programming language really) requires the  same quote form on the beginning and end of the line, and any of the  same quote used inside the text/string must be escaped so it knows to  treat it literally instead of as the end of the text/string.


....  so this all begs the question ... what's the actual contents of your tpl_social_media.php template file?
29 Apr 2013, 1:58 AM
#15
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

OMG! I saw that in the original tutorial but it didn't soak in that this was verbatim. Of course I went out of compliance and just typed anything <h3>Facebook</h3> in the file. My bad. My head is rattling but it has sunk in. So with that in hand, say I want to write a simple PHP script and use the output as content. Will there be a way to do that?

29 Apr 2013, 3:05 AM
#16
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Question after following the Custom Sidebox Tutorial in the wiki

Have your PHP script put its output into the $content variable, instead of using echo.

29 Apr 2013, 1:32 PM
#17
bobmeetin avatar

bobmeetin

New Zenner

Join Date:
Jan 2006
Posts:
57
Plugin Contributions:
0

Re: Question after following the Custom Sidebox Tutorial in the wiki

Time to express gratitude and close the loop. I have a working sample with PHP. In the template file:

<?php
$query = "select artists_name, artists_id from record_artists";
$result = mysql_query( $query );
$row = mysql_fetch_array($result);
$artists_id = ($row['artists_id']);
$artists_name = ($row['artists_name']);
$content = "ID: $artists_id / Name: $artists_name";
?>

Outputs:

ID: 1 / Name: The Russ Tippins Band

Incidentally, I wrote a short bash shell script that creates the 3 necessary files based upon the template name, header, etc you choose. Anything that I am likely to do repeatedly like this becomes either a PHP or shell script. If anyone is interested I can post it.

Possible custom sidebox usage - I'm thinking about writing a PHP script to grab and sort out a series of EZPages that I would call latest articles. This would eliminate the need of having to regularly edit a sidebox.

So, related question, how do you get a request over to the developers to enhance EzPages? Categories would be really really useful.