Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Passing variables ... revisited

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 11-25-2002, 11:25 PM
 
mgale mgale is offline
 

Newbie
  
Join Date: Sep 2002
Posts: 5
 

Default Passing variables ... revisited

Having spent 6 hours trying to figure this out I now appeal to the knowledgable individuals on this list ....

Standard way to call up products is to click on the category link which is <a href="home.php?cat={ $categories[cat_num].categoryid }">.

This calls home.php which "requires" a bunch of other php pages and ultimately displays home.tpl, which in turn calls subcategories.tpl, which then calls products.tpl, and the products are displayed. the "cat={ $categories[cat_num].categoryid }" is apparently what assigns the category variable and keeps it so the correct subcategories and/or products are displayed.

What I want to do is have each category call a unique page, which I can then customize (and search engine optimize) for THAT particular category.

What I've done so far:

Changed the link to: <a href="category{ $categories[cat_num].categoryid }.php"> which calls, for example, category1.php.

Then I copied home.php and renamed it category1.php, and changed the call to display category1.tpl (instead of home.tpl).

I copied and renamed home.tpl to category1.tpl.

So, instead of going home.php?cat=1 --> home.tpl, I have the exact same files called as category1.php --> category1.tpl.

Everything displays fine ... EXCEPT I CANNOT figure out how to get the variable of the category number passed through the php (and/or smarty) so the variable controls WHICH subcategories and products are displayed.

I've tried adding an assign to category1.php - didn't work. Tried adding an assign to category1.tpl (before it calls subcategories.tpl) - didn't work. I've probably tried a zillion different variations of trying to get the value of "1" (the categoryid) assigned as the $Cat variable. No go.

HELP!!!

It can't be THAT hard, can it? What am I missing here?

All help appreciated ... I am on a crunched time frame and beginning to really wig out.

Marie
Reply With Quote
  #2  
Old 11-26-2002, 08:33 AM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default passing variables

If I understand your problem, you are only lacking the passing of one more variable to the php code. On your href line, you can pass the variable using the ? as a separator. You can also pass multiple variables by separating them with the & symbol:

Code:
<a href="category{ $categories[cat_num].categoryid }.php?cat={$categories[cat_num].categoryid }">

You will then need to do something with $cat within your category1.php file, if you only want to pass it to the called tpl file, then you can do a smarty assign:

Code:
$smarty->assign("cat",$cat);

Before you make your call to the tpl. Let me know if I am not understanding your question.
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #3  
Old 11-26-2002, 09:13 AM
 
mgale mgale is offline
 

Newbie
  
Join Date: Sep 2002
Posts: 5
 

Default Passing variables

Hi Derrick,

You have the gist of it ... but the thing is that I want to set the value of "cat" WITHOUT having a ? is the a href.

So, the href calls category1.php,
which in turn displays category1.tlp,
which in turn calls subcategories.tlp
which calls products.tlp.

However, the subcategories.tlp and products.tpl are looking for the value of the variable "cat" (or "$Cat") to determine which category of subcategories and products to display.

In the original code, that variable value is set via the a href call, as you noted in your code.

So I need to figure out a different way to set that value, somewhere within category1.php or category1.tpl. Because category1.php and category1.tpl will ONLY be called when that link is clicked, I thought I could hard set the value, with
Code:
assign name=cat value=1
or
Code:
$Cat = 1

but I must have either the syntax or the location for it wrong.

Suggestions on where I should put it and what it should say?

Marie
__________________
Marie Gale
www.forsoapmakers.com
Reply With Quote
  #4  
Old 11-26-2002, 10:24 AM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default passing and assigning variables

I'm still not clear on why you can't use the value posted through the a href, but will focus no answering your question!

In category1.php you can assign $cat a value two different ways:

Code:
$cat = "1"; $smarty->assign("cat",$cat);

OR

Code:
$smarty->assign("cat","1");

I haven't done the latter, but should work fine.

I "believe" that the assign that you have been trying inside the .tpl will only remain as a local variable from within the .tpl itself. The only way to get it from the .tpl would be through a http post (standard html hidden variables) or by passing it as a parameter to the .php code call using the ? syntax originally discussed.

Does that help?
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #5  
Old 11-26-2002, 10:51 AM
 
mgale mgale is offline
 

Newbie
  
Join Date: Sep 2002
Posts: 5
 

Default Passing Variables

Oh, Derrick, you are the most wonderful!!!

I used the code and - voila - it worked. I must have tried every variation EXCEPT that one!

To explain my reasoning ...

Search engines cannot index pages that are called with a ? in the URL, but it can index the result from *.php. I want to have a unique page for each category, so I can optimize for that category, have it found by a search engine AND have a direct link, with no passed variables, possible.

My existing site category pages are well-ranked and I don't want to loose that. I'll be able to keep them with a 301 permanent re-direct now that I can have a specific, indexable page that the re-direct points to.

Again, thank you, thank you, thank you!

Marie
Reply With Quote
  #6  
Old 11-26-2002, 07:51 PM
 
derrick92130 derrick92130 is offline
 

Advanced Member
  
Join Date: Nov 2002
Location: San Diego, California USA
Posts: 68
 

Default Yeah!

Marie,

I'm glad that worked for you. That may explain why my sites rank so poorly in the search engines!

-Derrick
__________________
-Derrick
FreeRangeMinds, LLC
Reply With Quote
  #7  
Old 01-02-2004, 06:03 AM
 
SpeedWorx! Tech SpeedWorx! Tech is offline
 

Newbie
  
Join Date: Feb 2003
Posts: 4
 

Default Re: Passing Variables

Quote:
Originally Posted by mgale
Oh, Derrick, you are the most wonderful!!!

I used the code and - voila - it worked. I must have tried every variation EXCEPT that one!

To explain my reasoning ...

Search engines cannot index pages that are called with a ? in the URL, but it can index the result from *.php. I want to have a unique page for each category, so I can optimize for that category, have it found by a search engine AND have a direct link, with no passed variables, possible.

My existing site category pages are well-ranked and I don't want to loose that. I'll be able to keep them with a 301 permanent re-direct now that I can have a specific, indexable page that the re-direct points to.

Again, thank you, thank you, thank you!

Marie

Any chance you could include the code you finally used? This is exactly what I would like to do as well....

Thanks!
Reply With Quote
  #8  
Old 01-07-2004, 04:40 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Same here! I have been trying to take care of that myself. If you would care to do so, we would all appreciate posting what you have done, or at least hint at it if you lack the time.

Thanks!
Reply With Quote
  #9  
Old 01-07-2004, 09:43 PM
  Owl's Avatar 
Owl Owl is offline
 

Advanced Member
  
Join Date: Mar 2003
Location: Sweden
Posts: 92
 

Default

Well, this is why you use a Catalog as well, then it will index everything...
and ofcourse you need to edit the catalog abit, since it's not fully optimised atm...
__________________
-----------------------------------
4.2 rox...

http://www.fivestar.nu | www.nystil.se | www.hidealite.se
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:13 PM.

   

 
X-Cart forums © 2001-2020