Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Multiple templates using STS


Iggy

Recommended Posts

Multiple templates using STS

 

Hey there!

 

I've been banging my head against this for a few months now and hoping someone can give me a definitive answer.

 

Is there a way to STS pick up a category template across entire categories and all products in that category? I'd be interested to hear from anyone that actually has that working.

 

I've tried Steve Oliveira's fix

 

OPEN
/includes/sts_display_output.php
FIND: (around line 108)

if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
}

ADD AFTER

// Check to see if there are universal templates for parent categories
else {
// get all subcategories and parent category
$sts_all_cats = explode("_", $sts_cpath);
$num_all_cats = count($sts_all_cats);

// Load nearest parent category to the child
for ($i=1; $i<$num_all_cats; $i++) {
array_pop($sts_all_cats);
$sts_cpath = implode("_", $sts_all_cats);
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
$i=$num_all_cats;
}
}
}

 

No go. I've tried Greg K's fix

 

in sts_display_output.php:

Replace:

// Look for category-specific template file like "index.php_1_17.html"
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
//echo "$sts_check_file<BR>";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
}

With:

while ($sts_cpath != "")
{
// Look for category-subcategory-specific template file like "index.php_1_17.html"
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
//echo "$sts_check_file<BR>";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
break;
} 
$sts_cpath = substr($sts_cpath, 0, (strrpos($sts_cpath, "_")));
}

 

No go. Took a look at

http://www.oscommerce.com/forums/index.php?sho...16entry378616

 

But it's crazier than just making individual templates for every product. (No offense to Jaxx)

 

So, to sum up, I'd like to find a way for STS to be smart enough to know that if

 

/catalog/product_info.php?cPath=21&products_id=28

 

doesn't have a specific template created for id=28 that it should fall back on the template for cpath=21.

 

Has anyone gotten such a thing to function and can explain or point me at the solution?

 

Thanks much,

Iggy

Edited by Iggy

Everything's funny but nothing's a joke...

Link to comment
Share on other sites

  • 3 weeks later...

Seems I was banging my head against the wrong wall all this time and the solution was present in the STS Display Output code all the time :-"

 

Here are some key words for people searching so they can find this thread

 

Simple Template System, STS Category, STS Categories, STS Templates, STS Multiple Templates

 

So essentially what I was looking to do was apply a template to an entire category and all of it's product pages using just one file. index.php_1.html, for example, should apply to

 

index.php?cPath=1

index.php?cPath=1_x

product_info.php?cPath=1_x&products_id=x

 

Currently STS doesn't do things this way. So the first thing to do is apply Greg K's fix for subcategories

 

in sts_display_output.php:

Replace:

// Look for category-specific template file like "index.php_1_17.html"
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
//echo "$sts_check_file<BR>";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
}

With:

while ($sts_cpath != "")
{
// Look for category-subcategory-specific template file like "index.php_1_17.html"
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
//echo "$sts_check_file<BR>";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
break;
} 
$sts_cpath = substr($sts_cpath, 0, (strrpos($sts_cpath, "_")));
}

 

Then you want to let STS know to apply that template to all the products in the category or subcategory when viewed with product_info.php. This is so simple I'm embarrassed I didn't spot it immediately. Anyways here's how you do that.

 

Find

/////////////////////////////////////////////
////// if product_info.php load data
/////////////////////////////////////////////
if ($scriptbasename == 'product_info.php') {
 require(STS_PRODUCT_INFO);
}

Replace with

/////////////////////////////////////////////
////// if product_info.php load data
/////////////////////////////////////////////
if ($scriptbasename == 'product_info.php') {
 // If no cPath defined, default to 0 (the home page)
 if ($cPath == "") {
$sts_cpath = 0; 
 } else {
       $sts_cpath = $cPath;
 }

while ($sts_cpath != "")
{
// Look for category-subcategory-specific template file like "index.php_1_17.html"
$sts_check_file = STS_TEMPLATE_DIR . "index.php_$sts_cpath.html";
//echo "$sts_check_file<BR>";
if (file_exists($sts_check_file)) {
// Use it
$sts_template_file = $sts_check_file;
break;
} 
$sts_cpath = substr($sts_cpath, 0, (strrpos($sts_cpath, "_")));
} 

}

// Open Template file and read into a variable
if (! file_exists($sts_template_file)) {
 echo "Template file doesn't exist: [$sts_template_file]";
}  else {
 echo "<!-- Using Template File [$sts_template_file) -->\n";
}

if (! $fh = fopen($sts_template_file, 'r')) {
echo "Can't open Template file: [$sts_template_file]";
}

$template_html = fread($fh, filesize($sts_template_file));
fclose($fh);

 

Wolla! Now your single category template will follow through all the way to your products. All I can say is duh and I hope this helps someone.

 

Iggy

Everything's funny but nothing's a joke...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...