Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 9 votes

[contribution] Simple Template System (sts)


5806 replies to this topic

#41 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 02:13

Vaiso, on Sep 21 2003, 01:03 PM, said:

The file sts_display_output.php was present in my V1.4 download and has been uploaded with the other files.
You can view the error at www.vaiso.com/catalog

Just to be sure I have copied the last lines of my configure.php file for you to see.
I am terribly sorry for wasting your time on such a trivial issue.

// define our database connection
  define('DB_SERVER', ''); // eg, localhost - should not be empty for productive servers
  define('DB_SERVER_USERNAME', '');
  define('DB_SERVER_PASSWORD', '');
  define('DB_DATABASE', 'osCommerce');
  define('USE_PCONNECT', 'false'); // use persistent connections?
  define('STORE_SESSIONS', ''); // leave empty '' for default handler or set to 'mysql'
// STS: ADD: Define Simple Template System files
  define('STS_START_CAPTURE', DIR_WS_INCLUDES . 'sts_start_capture.php');
  define('STS_STOP_CAPTURE', DIR_WS_INCLUDES . 'sts_stop_capture.php');
  define('STS_RESTART_CAPTURE', DIR_WS_INCLUDES . 'sts_restart_capture.php');
  define('STS_TEMPLATE', DIR_WS_INCLUDES . 'sts_template.html');
  define('STS_DISPLAY_OUTPUT', DIR_WS_INCLUDES . 'sts_display_output.php');
// STS: EOADD
?>
I suspect that your problem is that you are installing the STS files before actually configuring the system's database.

In the configure.php file listed below none of your settings are present.

Try this:

1) Remove everything
2) Install a clean copy of osC 2.2MS2
3) Run the install program to establish that your database works. Go and make sure that your osC installation works.
4) THEN, once you know that everything works, copy the STS files in place
5) Copy the last few lines from the configure-SAMPLE.php onto the end of your /catalog/includes/configure.php file:

// STS: ADD: Define Simple Template System files
  define('STS_START_CAPTURE', DIR_WS_INCLUDES . 'sts_start_capture.php');
  define('STS_STOP_CAPTURE', DIR_WS_INCLUDES . 'sts_stop_capture.php');
  define('STS_RESTART_CAPTURE', DIR_WS_INCLUDES . 'sts_restart_capture.php');
  define('STS_TEMPLATE', DIR_WS_INCLUDES . 'sts_template.html');
  define('STS_DISPLAY_OUTPUT', DIR_WS_INCLUDES . 'sts_display_output.php');
// STS: EOADD

STS should only be installed in the /catalog/includes/, NOT in the /catalog/admin/ directories. STS is not used by the Admin system at all.

Also, whenever I upload a new file it will get a new version number to prevent the confusion that results from having multiple "versions" of the same version.

- Brian

PS: In the spirit of global technical lingo, the phrase "attribed them to 777" is a mixed metaphor. Attrib is a DOS/Windows command. The Unix/Linux command is "chmod" which is short for CHange MODe. The phrase would be "I chmod'ed the files to 777" or "I chmod 777'ed the files" or something like this. Just doin' my part in the Unixification of the world! ;)
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#42 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 05:31

Simple Template System (STS) v1.5 Released

Okay, I've put up a new version of STS that provides even more functionality than previous versions.

Major Change: Added $urlcat_xxxx variables to let you link directly to a category by Name or by numeric cPath (as seen in the URL). This lets you easily create links to category pages by text or images or imagemaps for a menu. Use a link like $urlcat_Mice or urlcat_1_9 to link directly to a particular category.

Created a sts_user_code.php so you can add new boxes and other template variables without having to mess with the other files. You will need to add the STS_USER_CODE definition to your configure.php file (see README.txt).

Added the name of the template file to the debugging output to make troubleshooting easier.

Added new TIPS section to README.txt file for ways to help make debugging templates even easier.

The errors and warnings now show in the $content section of the template. It was not displayed in previous versions which could lead to configuration problems.

A few other changes to the README.txt file to help with installation.

That's pretty much it. Hopefully I didn't mess anything up with my 1:30AM build! :)

Enjoy!

- Brian
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#43 Vaiso

  • Community Member
  • 52 posts
  • Real Name:Geoff Cox

Posted 22 September 2003, 19:55

Thanks for the advice.
I have done exactly as you suggested but still receive the same error.If I copy back the old configure.php file everything works fine.
Is there any way that someone could take a look at my code as I am going mad here.

#44 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 20:43

Vaiso, on Sep 22 2003, 02:55 PM, said:

Thanks for the advice.
I have done exactly as you suggested but still receive the same error.If I copy back the old configure.php file everything works fine.
Is there any way that someone could take a look at my code as I am going mad here.
You need to copy these lines to the end of your working configure.php file:

// STS: ADD: Define Simple Template System files
  define('STS_START_CAPTURE', DIR_WS_INCLUDES . 'sts_start_capture.php');
  define('STS_STOP_CAPTURE', DIR_WS_INCLUDES . 'sts_stop_capture.php');
  define('STS_RESTART_CAPTURE', DIR_WS_INCLUDES . 'sts_restart_capture.php');
  define('STS_TEMPLATE', DIR_WS_INCLUDES . 'sts_template.html');
  define('STS_DISPLAY_OUTPUT', DIR_WS_INCLUDES . 'sts_display_output.php');
  define('STS_USER_CODE', DIR_WS_INCLUDES . 'sts_user_code.php');
// STS: EOADD

(the STS_USER_CODE is new to v1.5, but won't hurt if you have an earlier version).

It sounds like you are losing your settings for your database connections when you replace your working configure.php file with the configure-SAMPLE.php one. You aren't supposed to copy the configure-SAMPLE.php file over top of the configure.php file, because you clobber your database settings that you have defined in these lines (in configure.php):

// define our database connection
  define('DB_SERVER', 'localhost'); // eg, localhost - should not be empty for productive servers
  define('DB_SERVER_USERNAME', 'yourdbusername');
  define('DB_SERVER_PASSWORD', 'yourdbpassword');
  define('DB_DATABASE', 'yourdatabasename');
  define('USE_PCONNECT', 'false'); // use persistent connections?
  define('STORE_SESSIONS', 'mysql'); // leave empty '' for default handler or set to 'mysql'

(The yourdbusername and other values should actually contain the settings that are appropriate for your server.)

Hope this helps!

- Brian
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#45 Vaiso

  • Community Member
  • 52 posts
  • Real Name:Geoff Cox

Posted 22 September 2003, 21:37

Thanks for your help.
I checked the configure file and the database details were indeed missing.

One quick point - I am awful with coding but do want to control the design layout hence the reason for using your contribution.
Am I correct in thinking that any alteraion to the template file will be seen in all OSCommerce pages?
My sincere thanks for your help.

#46 bottlerocket

  • Community Member
  • 8 posts
  • Real Name:Ben Aultowski
  • Location:Boone, NC

Posted 22 September 2003, 21:46

Hrm. I seem to be having a problem with the STS_USER_CODE. I believe I have it configured correctly in the file:

   $sts_block_name = 'articlebox';
   require(STS_START_CAPTURE);
   require(DIR_WS_BOXES . 'articlecat.php');
   require(STS_STOP_CAPTURE);

But in the template, it just displays the variable name as &articlebox. You can see this at http://dev.golfcarcatalog.com/catalog/index.php.

Any ideas?

#47 devosc

  • Community Member
  • 1,250 posts
  • Real Name:devosc

Posted 22 September 2003, 23:00

Hi Brian,

Thanks for the contribution.

I downloaded the STS-1_5 zip file and read the readme file which seemed ok but what I couldn't see was how the html_template actually begins to interact with php and oscommerce. For example in the default index.php file one is required to include the application_top and bottom files.

Would it be possible to see how from creating the template, in which I assume one expects to see the $declaration - knowing that that in php the correct reference is displayed, it is then actually implemented as a php file via a sample php file?

Thanks,

Greg.
"Any fool can know. The point is to understand." -- Albert Einstein

#48 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 23:04

Vaiso, on Sep 22 2003, 04:37 PM, said:

Thanks for your help.
I checked the configure file and the database details were indeed missing.

One quick point - I am awful with coding but do want to control the design layout hence the reason for using your contribution.
Am I correct in thinking that any alteraion to the template file will be seen in all OSCommerce pages?
My sincere thanks for your help.
You are correct. The changes will be applied to all /catalog/ pages, except pop-up windows. Admin pages will not be affected.

- Brian
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#49 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 23:12

bottlerocket, on Sep 22 2003, 04:46 PM, said:

Hrm. I seem to be having a problem with the STS_USER_CODE. I believe I have it configured correctly in the file:

   $sts_block_name = 'articlebox';
   require(STS_START_CAPTURE);
   require(DIR_WS_BOXES . 'articlecat.php');
   require(STS_STOP_CAPTURE);

But in the template, it just displays the variable name as &articlebox. You can see this at  http://dev.golfcarcatalog.com/catalog/index.php.

Any ideas?
My apologies, I ommitted a the code that adds it to the template. The sts_user_code.php commented out code should have read like this:

  // $sts_block_name = 'newthingbox';
  // require(STS_START_CAPTURE);
  // require(DIR_WS_BOXES . 'new_thing_box.php');
  // require(STS_STOP_CAPTURE);
  // $template['newthingbox'] = strip_unwanted_tags($sts_block['newthingbox'], 'newthingbox');

Copy the lines and uncomment them to do whatever you want.

Change your file to read like this (I just added the last line):

   $sts_block_name = 'articlebox';
   require(STS_START_CAPTURE);
   require(DIR_WS_BOXES . 'articlecat.php');
   require(STS_STOP_CAPTURE);
   $template['articlebox'] = strip_unwanted_tags($sts_block['articlebox'], 'articlebox');

Hope this helps!

- Brian
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#50 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 22 September 2003, 23:30

gregbaboolal, on Sep 22 2003, 06:00 PM, said:

Hi Brian,

Thanks for the contribution.

I downloaded the STS-1_5 zip file and read the readme file which seemed ok but what I couldn't see was how the html_template actually begins to interact with php and oscommerce. For example in the default index.php file one is required to include the application_top and bottom files.

Would it be possible to see how from creating the template, in which I assume one expects to see the $declaration - knowing that that in php the correct reference is displayed, it is then actually implemented as a php file via a sample php file?

Thanks,

Greg.

Here's how it works. In application_top.html it calls the STS_START_CAPTURE script, which calls the PHP function ob_start() which captures the output buffer and saves it to a string in $sts_block[$stringname] defined before it calls STS_STOP_CAPTURE.

It does the same process for each of the files replaced by this contribution. In the column_left.php function, there is a separate set of capture and save commands around each of the BOX-creation functions.

When it's all done, application_bottom.php calls sts_display_output.php which goes through the saved variables and removes some of the formatting code (starting and ending <td> and <tr> tags) that is used by OSC but isn't wanted by the template system.

It then reads the STS_TEMPLATE file into a single string variable in memory.

Then it sorts all the $template[$variablename] variables by the string-length of the $variablename, from largest to smallest. It then replaces any occurance of $variablename in the saved STS_TEMPLATE string with the values stored in the the corresponding $template[$variablename] string.

Then it prints out the saved & find-and-replaced STS_TEMPLATE string to the browser.

Does this answer your question?

- Brian

Edited by DiamondSea, 22 September 2003, 23:31.

Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#51 compugeek2003

  • Community Member
  • 50 posts
  • Real Name:Eric Stamper
  • Location:USA

Posted 22 September 2003, 23:36

Brian,

Thanks for the update. It looks like you have added some great new functionality. Having the errors and warnings show on the page will be very helpful.

Keep up the good work!

Eric Stamper

#52 devosc

  • Community Member
  • 1,250 posts
  • Real Name:devosc

Posted 23 September 2003, 01:55

Sir, it's very smart.

Thanks,

Greg.
"Any fool can know. The point is to understand." -- Albert Einstein

#53 MurrayM

  • Community Member
  • 296 posts
  • Real Name:Murray Mintz
  • Location:Santa Monica, California

Posted 23 September 2003, 01:55

Brian,

I've approached this contribution with great enthusiasm as I have been wanting to create shops which don't look like out of the box OSC, but love the cart and everything about the community. I have done the installation but get the following error messages:

Warning: main(includes/sts_user_code.php): failed to open stream: No such file or directory in /www1/guatemalafairtrade.com/html/catalog/includes/sts_display_output.php on line 82

Fatal error: main(): Failed opening required 'includes/sts_user_code.php' (include_path='.:/usr/local/lib/php/') in /www1/guatemalafairtrade.com/html/catalog/includes/sts_display_output.php on line 82


Do I need to install WebMakers.com Changed: Header Tag Controller v1.0?

I have the latest MS2 version which was working perfectly. Should it have the header tag controller built into it? Or do I need to install Linda's hearder tag controller. Any advice would be helpful.

thanks,
Murray

#54 devosc

  • Community Member
  • 1,250 posts
  • Real Name:devosc

Posted 23 September 2003, 02:07

Would it be possible to have a html template for each respective php file, for example, index.html, contact_us.html etc?
"Any fool can know. The point is to understand." -- Albert Einstein

#55 bleu

  • Community Member
  • 8 posts
  • Real Name:Kat

Posted 23 September 2003, 06:59

Quote

I've approached this contribution with great enthusiasm as I have been wanting to create shops which don't look like out of the box OSC, but love the cart and everything about the community. I have done the installation but get the following error messages:

Warning: main(includes/sts_user_code.php): failed to open stream: No such file or directory in /www1/guatemalafairtrade.com/html/catalog/includes/sts_display_output.php on line 82

Fatal error: main(): Failed opening required 'includes/sts_user_code.php' (include_path='.:/usr/local/lib/php/') in /www1/guatemalafairtrade.com/html/catalog/includes/sts_display_output.php on line 82

Do I need to install WebMakers.com Changed: Header Tag Controller v1.0?

I have the latest MS2 version which was working perfectly. Should it have the header tag controller built into it? Or do I need to install Linda's hearder tag controller. Any advice would be helpful.

Make sure there is no space or hard return at the end of the file in 'includes/sts_user_code.php'

This seems to cause this error.

#56 Vaiso

  • Community Member
  • 52 posts
  • Real Name:Geoff Cox

Posted 23 September 2003, 16:22

When using STS to alter the default template have I got complete freedom when it comes to graphical content?
What I mean is can I remove the OS commerce logo, add my own plus additional graphics in the navigation bar. If so do I reference the images using http://pathtoimages or relative paths?

Also is the table created to hold that actual page details a fixed width or will it fot within the design widths I use?

Many thanks

#57 compugeek2003

  • Community Member
  • 50 posts
  • Real Name:Eric Stamper
  • Location:USA

Posted 23 September 2003, 19:15

Vaiso,

Quote

When using STS to alter the default template have I got complete freedom when it comes to graphical content?
What I mean is can I remove the OS commerce logo, add my own plus additional graphics in the navigation bar. If so do I reference the images using http://pathtoimages or relative paths?

You can plug in additional graphics to the template page. You should be able to use either full paths or relative paths for this. By default, in the $headercontent template variable there is a reference to the base address to your page. This will allow the use of relative url's.


Quote

Also is the table created to hold that actual page details a fixed width or will it fot within the design widths I use?

The table widths are controlled in the sts_template.html file. For example around line 27 you would see this code:

 <td width="125" valign="top">

You could change the default value of 125 pixels to whatever you want. This would change the width of the left column. The main content section, the right column, and any other parts of the page could be conrolled similarly.


Eric Stamper

#58 DiamondSea

  • Community Member
  • 267 posts
  • Real Name:Brian Gallagher
  • Location:Baltimore, MD

Posted 23 September 2003, 20:15

Quote

When using STS to alter the default template have I got complete freedom when it comes to graphical content?
What I mean is can I remove the OS commerce logo, add my own plus additional graphics in the navigation bar. If so do I reference the images using http://pathtoimages or relative paths?

You can plug in additional graphics to the template page.  You should be able to use either full paths or relative paths for this.  By default, in the $headercontent template variable there is a reference to the base address to your page.  This will allow the use of relative url's.

You have complete freedom to lay out your page however you like. The sts_template.html included with the package is just a sample that looks like the default OSC catalog so people can get familiar with what all the $variables do.

I recommend using absolute URL's (starting with just a slash or http://) for your stylesheet and image links. This will make it easier to debug your output, because you will be able to simply point your browser to http://yourdomain.com/catalog/includes/sts_template.html and see what it will look like, showing the $variables in their places.

It will work with relative links, but you won't be able to preview your page the same way.

Quote

Also is the table created to hold that actual page details a fixed width or will it fot within the design widths I use?

The page contents in the $contents variable are enclosed in a table with a width of 100%, so it should automatically scale to whatever you have it in.

Quote

The table widths are controlled in the sts_template.html file.  For example around line 27 you would see this code:

 
 <td width="125" valign="top">

You could change the default value of 125 pixels to whatever you want. This would change the width of the left column.  The main content section, the right column, and any other parts of the page could be conrolled similarly.

FYI, the various boxes are set up with width=100%, so they will become wider to suit the size of the table cell that they are contained in. So if you make the column_left table width=250, all the boxes will become twice as wide. This can be handy when working with long category names or deeply nested categories (but you should avoid having either of those as a usability issue).

Additionally, you can get rid of the $categorybox altogether and use an image map or other links for your navigation system if you want by using the <a href="$cat_XXX"> technique (in v1.5+) to link directly to a category page without having to use the $categorybox control.

What you get your design up, post a link to the site and the template page so other people can see how it works.

Thanks!

- Brian
Simple Template System (STS)
Layout your site with 1 (or more) HTML file!
Download STS: http://www.oscommerce.com/community/contributions,1524
Support: http://forums.oscommerce.com/index.php?showtopic=58541

#59 travisb

  • Community Member
  • 143 posts
  • Real Name:Travis B
  • Gender:Male
  • Location:Richmond, VA

Posted 23 September 2003, 20:17

I installed Simple Template System and now the <html>, <head>, etc. tags are showing up twice.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>mysite</title><base href="http://www.mysite.com/">

<!-- start get_javascript(applicationtop2header) //-->
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="LTR" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>mysite</title>
<base href="http://www.mysite.com/">
<link rel="stylesheet" type="text/css" href="stylesheet.css">

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->

<!-- end get_javascript(applicationtop2header) //-->

<link rel="stylesheet" type="text/css" href="$stylesheet.css">
</head>
<body>


#60 mktwain124

  • Community Member
  • 9 posts
  • Real Name:Marko
  • Location:Michigan

Posted 23 September 2003, 20:54

Thanks, Brian, for sharing all your hard work and providing this contribution. The master template system is an ingenious way to allow considerable layout/design flexibility without requiring changes to the core program files.

We have all spent countless hours trying to customize our own storefronts by changing the code -- usually with considerable frustration and complications. Your contribution has simplified this process immensely (particularly for Dreamweaver template users!) and without any apparent performance slowdowns. It also provides endless possibilities for displaying other types of infobox creations from customized template variables.

Thanks again. Your efforts are greatly appreciated!