Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Adding new element to main or other page

Adding new element to main or other page

Views: 1,969

Results 1 to 20 of 21
10 Oct 2012, 3:32 PM
#1
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Adding new element to main or other page

I'm trying and failing to customize the Zencart interface a bit more than the template system seems to allow. I hope I'm just missing something.

I created a CUSTOM folder (not using that exact name) under (my site, ZC 1.5.0)/includes/templates/ and copied tpl_main_page.php there. I edited that tpl_main_page.php copy and added a line:

<h3>hello world</h3>

Here's the bit of code where I added it-first line at "body id" is line 53:

<body id="<?php echo $body_id . 'Body'; ?>"<?php if($zv_onload !='') echo ' onload="'.$zv_onload.'"'; ?>> <?php if (SHOW_BANNERS_GROUP_SET1 != '' && $banner = zen_banner_exists('dynamic', SHOW_BANNERS_GROUP_SET1)) { if ($banner->RecordCount() > 0) { ?> <div id="bannerOne" class="banners"><?php echo zen_display_banner('static', $banner); ?></div> <h3>hello world</h3> <?php } } ?>

But my text appears nowhere on the main page.

I tried likewise with tpl_header.php; same result.

Why don't I see a change, and how can I get such a change? Once I know how to do "hello world", I hope to add an image just beneath the main banner (actually substituting for it) with a linkable map that I control.

10 Oct 2012, 4:04 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Adding new element to main or other page

I created a CUSTOM folder (not using that exact name) under (my site, ZC 1.5.0)/includes/templates/
One must match folders & contents to that of template_default

So tpl_main_page.php belongs in a folder named "common" under/in your custom template folder

10 Oct 2012, 4:07 PM
#3
stevesh avatar

stevesh

Black Belt

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

Re: Adding new element to main or other page

You also need to have a template_info.php file in the template's root directory (includes/templates/custom) and select the template in Admin - Tools - Template Selection

11 Oct 2012, 3:05 PM
#4
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Aha, thank you. Putting the tpl_header.php file into the "common" subdirectory makes my little code bit display. However, placing tpl_main.php there too does not display anything.

I do have a template_info.php in the proper place.

11 Oct 2012, 8:55 PM
#5
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

placing tpl_main.php there too does not display anything.Then you have made an error, whether in filename or location or syntax of your new code we can't say without more information. What exactly did you do with tpl_main_page.php?

12 Oct 2012, 2:46 PM
#6
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

gjh42, thanks for replying. In tpl_main_page, I make the change below line 58 (where this snippet starts at line 53):

<body id="<?php echo $body_id . 'Body'; ?>"<?php if($zv_onload !='') echo ' onload="'.$zv_onload.'"'; ?>> <?php if (SHOW_BANNERS_GROUP_SET1 != '' && $banner = zen_banner_exists('dynamic', SHOW_BANNERS_GROUP_SET1)) { if ($banner->RecordCount() > 0) { ?> <div id="bannerOne" class="banners"><?php echo zen_display_banner('static', $banner); ?></div> <h3>xping_tpl_main_page</h3> <?php } } ?>

I have changed "hello world" to a more easily searchable string. I noticed that my string is inside a structure that seems to be executed when banners are displayed, so I tried turning the banners on, but got the same result.

I also added another string just below the snippet shown here. That finally gave me a result, at the top of the page. It is located outside the principal area of display, so is not useable, but I can experiment further.

If it's not against Zencart policy in some way, I suggest some FAQ or tutorial on adding display elements interspersed with those in the site layout, as I am trying to do. Seems it might be a useful, alternative means of controlling appearance and function.

12 Oct 2012, 5:36 PM
#8
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

You have to not just turn bannergroup1 on, but have a banner in it to display, in order for the code to execute.

You might just better put your code outside that conditional (as your last comment suggests), unless you really only want it to execute when the banner displays.

12 Oct 2012, 5:40 PM
#9
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

And yes, as that tutorial describes, you generally want to add custom display code in specific page element files rather than tpl_main_page.php, unless you want your new element outside the normal page elements.

15 Oct 2012, 12:37 PM
#10
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Experimenting with tpl_header, I can put my little strings at a number of places above the second "Home" link to the main screen and the "Welcome..." message. However, making similar changes to the tpl_footer file does not give me anything else - I can't change anything in the region of the products listing. The obvious points to try seem clear: at the eof/bof comments in tpl_footer.php. Why do these changes make no difference?

I am starting from the barebones template, if that's a clue. Also, adding the tpl_header changes seems to make the banners vanish, although I have all banners turned on.

And I think I don't want to use tpl_main for anything here.

Thanks again for your help!

15 Oct 2012, 1:42 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

If you want to add elements to the product listing page (and not to other pages) try /includes/templates/your_template/templates/tpl_index_product_list.php.

Adding elements in tpl_header.php will not affect the banners unless you are doing something wrong. It's not possible to say what without seeing the edited file.

15 Oct 2012, 2:13 PM
#12
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Actually, I want to turn the banners off - sorry if I misled you.

I want to put an image, with links I control, either above or below the existing HEADER_LOGO_IMAGE. That I can put text links in the tpl_header seems to imply that I can put such an image where I want it. Then, I want to put more linked images below the part that displays the product boxes. I thought tpl_footer would permit that, but I can't seem to control anything with that file, and I'm wondering why.

15 Oct 2012, 3:24 PM
#13
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

You can add elements with tpl_footer.php, as long as you code them right. Thus, you have some error which we cannot advise on without seeing your copy of the file.

If you want the new elements on all pages, tpl_footer.php is the right file to edit; if not, use tpl_index_product_list.php or whatever other file controls the particular page content.

15 Oct 2012, 3:42 PM
#14
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Here's my tpl_footer. The only changes are the <h3>xping*</h3> lines added, looking for where they might show up:

<?php /** * Common Template - tpl_footer.php * * this file can be copied to /templates/your_template_dir/pagename<br /> * example: to override the privacy page<br /> * make a directory /templates/my_template/privacy<br /> * copy /templates/templates_defaults/common/tpl_footer.php to /templates/my_template/privacy/tpl_footer.php<br /> * to override the global settings and turn off the footer un-comment the following line:<br /> * <br /> * $flag_disable_footer = true;<br /> * * @package templateSystem * @copyright Copyright 2003-2010 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: tpl_footer.php 15511 2010-02-18 07:19:44Z drbyte $ */ require(DIR_WS_MODULES . zen_get_module_directory('footer.php')); ?> <?php if (!isset($flag_disable_footer) || !$flag_disable_footer) { ?> <h3>xping_tpl_footer_1</h3> <!--bof-navigation display --> <div id="navSuppWrapper"> <div id="navSupp"> <ul> <li><?php echo '<a href="' . HTTP_SERVER . DIR_WS_CATALOG . '">'; ?><?php echo HEADER_TITLE_CATALOG; ?></a></li> <?php if (EZPAGES_STATUS_FOOTER == '1' or (EZPAGES_STATUS_FOOTER == '2' and (strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])))) { ?> <li><?php require($template->get_template_dir('tpl_ezpages_bar_footer.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_ezpages_bar_footer.php'); ?></li> <?php } ?> </ul> </div> </div> <!--eof-navigation display --> <h3>xping_tpl_footer_2</h3> <!--bof-ip address display --> <?php if (SHOW_FOOTER_IP == '1') { ?> <div id="siteinfoIP"><?php echo TEXT_YOUR_IP_ADDRESS . ' ' . $_SERVER['REMOTE_ADDR']; ?></div> <?php } ?> <!--eof-ip address display --> <h3>xping_tpl_footer_3</h3> <!--bof-banner #5 display --> <?php if (SHOW_BANNERS_GROUP_SET5 != '' && $banner = zen_banner_exists('dynamic', SHOW_BANNERS_GROUP_SET5)) { if ($banner->RecordCount() > 0) { ?> <div id="bannerFive" class="banners"><?php echo zen_display_banner('static', $banner); ?></div> <?php } } ?> <!--eof-banner #5 display --> <h3>xping_tpl_footer_4</h3> <!--bof- site copyright display --> <div id="siteinfoLegal" class="legalCopyright"><?php echo FOOTER_TEXT_BODY; ?></div> <!--eof- site copyright display --> <?php } // flag_disable_footer <h3>xping_tpl_footer_5</h3> ?>
15 Oct 2012, 3:51 PM
#15
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Also, a similar set of changes produced visible results in tpl_header.

15 Oct 2012, 4:05 PM
#16
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

Those edits will work if you have saved the edited file to the right location. Where is it now, and are the edits in it?

15 Oct 2012, 4:56 PM
#17
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

It's in (((store)))/includes/templates/barebones/common

I did a diff -wis of the original and modified footers:
24a25

<h3>xping_tpl_footer_1</h3>

38c39
<

<h3>xping_tpl_footer_2</h3>

48c49
<

<h3>xping_tpl_footer_3</h3>

60c61
<

<h3>xping_tpl_footer_4</h3>

66a68

<h3>xping_tpl_footer_5</h3>
15 Oct 2012, 5:01 PM
#18
gjh42 avatar

gjh42

Black Belt

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

Re: Adding new element to main or other page

I don't know what to say. It sounds like you have the right location (you are using barebones template, right?) and there is nothing wrong with those edits. You're sure that the copy on the server now has the edits?

15 Oct 2012, 8:49 PM
#19
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

Futher observations: at one point I lost the entire page, even when the main, header and footer files in barebones/common were renamed to e.g. 1.tpl_header.php. Blank grey screen. Does zencart see and act on files of such nonstandard names?

Deleting everything in barebones/common brought the page back. Putting the modified tpl_footer back in makes the banners disappear (all predefined banners are turned on via the admin). Also the "Your IP Address is", copyright, and "powered by zen cart" material at the bottom disappears. Is that a clue, maybe?

Looking further, with all banners off, and no tpl_header, I get the IP Address, copyright, and zen-cart bottom material. If I then add tpl_header, the bottom matter goes away.

15 Oct 2012, 8:54 PM
#20
dream_mike avatar

dream_mike

New Zenner

Join Date:
May 2012
Posts:
38
Plugin Contributions:
0

Re: Adding new element to main or other page

I should have said: in the previous post, tpl_footer is the only file in barebones/common, I deleted the tpl_header.