| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Passing variables ... revisited | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
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 |
|||||||
#2
|
|||||||
|
|||||||
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:
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:
Before you make your call to the tpl. Let me know if I am not understanding your question.
__________________
-Derrick FreeRangeMinds, LLC |
|||||||
#3
|
|||||||
|
|||||||
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:
Code:
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 |
|||||||
#4
|
|||||||
|
|||||||
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:
OR Code:
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 |
|||||||
#5
|
|||||||
|
|||||||
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 |
|||||||
#6
|
|||||||
|
|||||||
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 |
|||||||
#7
|
|||||||
|
|||||||
Re: Passing Variables
Quote:
Any chance you could include the code you finally used? This is exactly what I would like to do as well.... Thanks! |
|||||||
#8
|
|||||||
|
|||||||
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! |
|||||||
#9
|
|||||||||
|
|||||||||
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 |
|||||||||
|
|||
X-Cart forums © 2001-2020
|