Using Smarty tags in User Defined Tags

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
okparrothead
Forum Members
Forum Members
Posts: 36
Joined: Sun Feb 12, 2006 10:42 pm

Using Smarty tags in User Defined Tags

Post by okparrothead »

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!
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
alby

Re: Using Smarty tags in User Defined Tags

Post by alby »

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!
Try with:

Code: Select all

global $gCms;
$smarty =& $gCms->GetSmarty();

switch ($smarty->get_template_vars('title')){
 case: ......
Alby
okparrothead
Forum Members
Forum Members
Posts: 36
Joined: Sun Feb 12, 2006 10:42 pm

Re: Using Smarty tags in User Defined Tags

Post by okparrothead »

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
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
alby

Re: Using Smarty tags in User Defined Tags

Post by alby »

okparrothead wrote: Thanks Alby,

No go.
On, my mistake.
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');
In template:

Code: Select all

{test}
Alby
okparrothead
Forum Members
Forum Members
Posts: 36
Joined: Sun Feb 12, 2006 10:42 pm

Re: Using Smarty tags in User Defined Tags

Post by okparrothead »

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.
"Contentment is a quality best suited for cows - not cowboys" -- Jimmy Buffet
alby

Re: Using Smarty tags in User Defined Tags

Post by alby »

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?
Try with (but remember title isn't unique, alias or id yes):

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;
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.
In template try with:

Code: Select all

{capture name=titlecapture}{title}{/capture}

{colors product=$titlecapture}
Alby
okparrothead
Forum Members
Forum Members
Posts: 36
Joined: Sun Feb 12, 2006 10:42 pm

Re: Using Smarty tags in User Defined Tags

Post by okparrothead »

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
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
alby

Re: Using Smarty tags in User Defined Tags

Post by alby »

okparrothead 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!
I'm glad to see that I've helped some people  ;D

Alby
Post Reply

Return to “CMSMS Core”