Hello SMS Gurus,
Have mercy on a Noob.
I'm adding some php code in a user defined tag, but I want to use a smarty page variable as a control.
This doesn't work:
switch ({title}){
case: ......
Any ideas?
Thanks for all your help!
Using Smarty tags in User Defined Tags
-
- Forum Members
- Posts: 36
- Joined: Sun Feb 12, 2006 10:42 pm
Using Smarty tags in User Defined Tags
Last edited by okparrothead on Wed May 16, 2007 7:29 pm, edited 1 time in total.
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
Re: Using Smarty tags in User Defined Tags
Try with:okparrothead wrote: Hello SMS Gurus,
Have mercy on a Noob.
I'm adding some php code in a user defined tag, but I want to use a smarty page variable as a control.
This doesn't work:
switch ({title}){
case: ......
Any ideas?
Thanks for all your help!
Code: Select all
global $gCms;
$smarty =& $gCms->GetSmarty();
switch ($smarty->get_template_vars('title')){
case: ......
-
- Forum Members
- Posts: 36
- Joined: Sun Feb 12, 2006 10:42 pm
Re: Using Smarty tags in User Defined Tags
Thanks Alby,
No go.
I put it all in the user defined tag, but same result.
Should I be putting the
global $gCms;
$smarty =& $gCms->GetSmarty();
part in the template?
Thanks for all your help
No go.
I put it all in the user defined tag, but same result.
Should I be putting the
global $gCms;
$smarty =& $gCms->GetSmarty();
part in the template?
Thanks for all your help
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
Re: Using Smarty tags in User Defined Tags
On, my mistake.okparrothead wrote: Thanks Alby,
No go.
This work:
UDT -> test
Code: Select all
global $gCms;
$smarty =& $gCms->GetSmarty();
echo '<br />page = '.$smarty->get_template_vars('page');
echo '<br />page_id = '.$smarty->get_template_vars('page_id');
echo '<br />page_name = '.$smarty->get_template_vars('page_name');
echo '<br />page_alias= '.$smarty->get_template_vars('page_alias');
Code: Select all
{test}
-
- Forum Members
- Posts: 36
- Joined: Sun Feb 12, 2006 10:42 pm
Re: Using Smarty tags in User Defined Tags
Thanks Alby,
So close!! The code you gave me works great!
I could echo the value of title, but I can't use it in the UDT code.
Let me explain further.
I have a series of product pages with different colors for each product. I've written a flat file of all the colors and a script that will get the correct colors depending on product.
I can make my script work fine if I plug in a variable for any one product. I could copy the same script for each product, with different product variables, and rename them as different UDTs. But -- I want to use a PHP switch so the same UDT would work for any product. I decided to use the page {title} (also the product title) as the switch variable.
How can I use the {title} of the page as a PHP variable in my UDT?
I read the user handbook and came up with these attempts:
Unless I had unknown spelling errors,
switch({title}) didn't work.
I tried {colors product={title}} in the template (to pass {title} as a variable named product for the UDT) and switch($params['product']) in the UDT named colors, but that didn't work.
I also tried {title assign=thiscolor} {colors product="$thiscolor"} in the template (to assign the value of {title} to $thiscolor as a variable for the UDT,) and swith($params['product']) in the UDT named colors, and that didn't work.
Do you know where I go from here?
Any help on this would be great.
So close!! The code you gave me works great!
I could echo the value of title, but I can't use it in the UDT code.
Let me explain further.
I have a series of product pages with different colors for each product. I've written a flat file of all the colors and a script that will get the correct colors depending on product.
I can make my script work fine if I plug in a variable for any one product. I could copy the same script for each product, with different product variables, and rename them as different UDTs. But -- I want to use a PHP switch so the same UDT would work for any product. I decided to use the page {title} (also the product title) as the switch variable.
How can I use the {title} of the page as a PHP variable in my UDT?
I read the user handbook and came up with these attempts:
Unless I had unknown spelling errors,
switch({title}) didn't work.
I tried {colors product={title}} in the template (to pass {title} as a variable named product for the UDT) and switch($params['product']) in the UDT named colors, but that didn't work.
I also tried {title assign=thiscolor} {colors product="$thiscolor"} in the template (to assign the value of {title} to $thiscolor as a variable for the UDT,) and swith($params['product']) in the UDT named colors, and that didn't work.
Do you know where I go from here?
Any help on this would be great.
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
Re: Using Smarty tags in User Defined Tags
Try with (but remember title isn't unique, alias or id yes):okparrothead wrote: Thanks Alby,
So close!! The code you gave me works great!
I could echo the value of title, but I can't use it in the UDT code.
Let me explain further.
I have a series of product pages with different colors for each product. I've written a flat file of all the colors and a script that will get the correct colors depending on product.
I can make my script work fine if I plug in a variable for any one product. I could copy the same script for each product, with different product variables, and rename them as different UDTs. But -- I want to use a PHP switch so the same UDT would work for any product. I decided to use the page {title} (also the product title) as the switch variable.
How can I use the {title} of the page as a PHP variable in my UDT?
Code: Select all
global $gCms;
$smarty =& $gCms->GetSmarty();
echo '<br />page = '.$smarty->get_template_vars('page');
echo '<br />page_id = '.$smarty->get_template_vars('page_id');
echo '<br />page_name = '.$smarty->get_template_vars('page_name');
echo '<br />page_alias= '.$smarty->get_template_vars('page_alias');
$pageinfo = &$gCms->variables['pageinfo'];
$title = $pageinfo->content_title;
echo '<br />title= '.$title;
In template try with:okparrothead wrote: I tried {colors product={title}} in the template (to pass {title} as a variable named product for the UDT) and switch($params['product']) in the UDT named colors, but that didn't work.
I also tried {title assign=thiscolor} {colors product="$thiscolor"} in the template (to assign the value of {title} to $thiscolor as a variable for the UDT,) and swith($params['product']) in the UDT named colors, and that didn't work.
Code: Select all
{capture name=titlecapture}{title}{/capture}
{colors product=$titlecapture}
-
- Forum Members
- Posts: 36
- Joined: Sun Feb 12, 2006 10:42 pm
Re: Using Smarty tags in User Defined Tags
Thanks Alby,
Mil Grazie!
You are the best!
You're right of course (Doh!) the title isn't necessarily unique, so I should change that. The alias is better.
Anyway, here's what worked:
global $gCms;
$smarty =& $gCms->GetSmarty();
$pageinfo = &$gCms->variables['pageinfo'];
switch($pageinfo->content_title)
in the UDT.
If I was there, I'd buy you some beer!! Thank you so much.
May there be a new Ferrari in your near future!
Peace,
OKParrothead
Mil Grazie!
You are the best!
You're right of course (Doh!) the title isn't necessarily unique, so I should change that. The alias is better.
Anyway, here's what worked:
global $gCms;
$smarty =& $gCms->GetSmarty();
$pageinfo = &$gCms->variables['pageinfo'];
switch($pageinfo->content_title)
in the UDT.
If I was there, I'd buy you some beer!! Thank you so much.
May there be a new Ferrari in your near future!
Peace,
OKParrothead
Last edited by okparrothead on Thu May 17, 2007 5:19 pm, edited 1 time in total.
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
Re: Using Smarty tags in User Defined Tags
I'm glad to see that I've helped some peopleokparrothead wrote: Thanks Alby,
Mil Grazie!
You are the best!
You're right of course (Doh!) the title isn't necessarily unique, so I should change that. The alias is better.
Anyway, here's what worked:
global $gCms;
$smarty =& $gCms->GetSmarty();
$pageinfo = &$gCms->variables['pageinfo'];
switch($pageinfo->content_title)
in the UDT.
If I was there, I'd buy you some beer!! Thank you so much.
May there be a new Ferrari in your near future!

Alby