Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Translate {php} code to 3.1 compliant

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
scorpster
Smarty n00b


Joined: 17 Feb 2012
Posts: 4

PostPosted: Fri Feb 17, 2012 12:01 pm    Post subject: Translate {php} code to 3.1 compliant Reply with quote

I am not a smarty template or php programmer.
I had somebody configure an existing package for me in 2010 but now the underlying package is using 3.1 smarty engine.

The following {php} code needs to be re-written/translated so that it works in the new environment.

{php}
if($_GET['b']==4){
$this->_tpl_vars['ppClass'] = 'class="hiddenDiv"';
}else{
switch($_GET['section']){
case 'price_plans':
$this->_tpl_vars['infoClass'] = 'class="hiddenDiv"';
break;
case 'personal_details':
$this->_tpl_vars['ppClass'] = 'class="hiddenDiv"';
break;
default:
break;
}
}
{/php}

Any help/suggestions/advice is greatly appreciated.
thanks,
C.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 17, 2012 2:57 pm    Post subject: Reply with quote

This can all be done in templates without {php}.

Code:
{if $smarty.get.b == 4}
  {assign var="ppClass" value='class="hiddenDiv"'}
{elseif $smarty.get.section == "price_plans"}
  {assign var="infoClass" value='class="hiddenDiv"'}
{elseif $smarty.get.section == "personal_details"}
  {assign var="ppClass" value='class="hiddenDiv"'}
{/if}
Back to top
View user's profile Send private message Visit poster's website
scorpster
Smarty n00b


Joined: 17 Feb 2012
Posts: 4

PostPosted: Fri Feb 17, 2012 3:19 pm    Post subject: Reply with quote

that's great - thanks ... now I've got passed that particular error, the next block "bad code" has emerged ... can you suggest proper edit for this for 3.1 compliance?:

{php}

$newAr = array(

'classified' => $this->_tpl_vars['cartLinks']['classified'],

'auction' => $this->_tpl_vars['cartLinks']['auction'],

'account_balance' => $this->_tpl_vars['cartLinks']['account_balance']

);

$this->_tpl_vars['cartLinks'] = $newAr;

{/php}
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Feb 17, 2012 5:12 pm    Post subject: Reply with quote

Code:
{$cartLinks = ['classified' => $cartLinks['classified'],
'auction' => $cartLinks['auction'],
'account_balance' => $cartLinks['account_balance']]}
Back to top
View user's profile Send private message
scorpster
Smarty n00b


Joined: 17 Feb 2012
Posts: 4

PostPosted: Fri Feb 17, 2012 5:56 pm    Post subject: Reply with quote

Thanks for helping me -- I can't say how much I appreciate it ...

I got somebody to help me find the full set of code statements from the template file that have the same {php} tag. These code snippets will rear up at some point to throw errors -- thank goodness there are smarter people than me out there!

Based on the help I've received so far (and trying to show forum members that I do want to learn and not just be an annoying "noob") am I correct in translating the following:
{php}
$newArr = array(
'active_ads' => $this->_tpl_vars['links']['active_ads'],
'expired_ads' => $this->_tpl_vars['links']['expired_ads'],
'favorites' => $this->_tpl_vars['links']['favorites'],
'current_bids' => $this->_tpl_vars['links']['current_bids'],
'ad_filters' => $this->_tpl_vars['links']['ad_filters'],
'signs_flyers' => $this->_tpl_vars['links']['signs_flyers'],
'Facebook_Feed' => $this->_tpl_vars['links']['Facebook_Feed']

);
$this->_tpl_vars['links'] = $newArr;
{/php}

to
{$newArr = ['active_ads' => $links['active_ads'], 'expired_ads' => $links['expired_ads'], 'favorites' => $links['favorites'], 'current_bids' => $links['current_bids'], 'ad_filters' => $links['ad_filters'], 'signs_flyers' => $links['signs_flyers'], 'Facebook_Feed' => $links['Facebook_Feed']]}

...
Not sure about the translation of this one though:


{php}
$this->_tpl_vars['orderItemLinks'] = array();
{/php}

... or this one ...

{php}
$newArray = array();
foreach($this->_tpl_vars['paymentGatewayLinks'] as $linkArray){
if($linkArray['link']=="index.php?a=29"){
continue;
}
$newArray[] = $linkArray;
}
$this->_tpl_vars['paymentGatewayLinks'] = $newArray;
{/php}

Help is very much appreciated.
thanks again.
C.
Back to top
View user's profile Send private message
scorpster
Smarty n00b


Joined: 17 Feb 2012
Posts: 4

PostPosted: Fri Feb 17, 2012 6:00 pm    Post subject: Reply with quote

oops ... found this one as well ...

{php}
$newArray = array();
foreach ($this->_tpl_vars[boxes] as $k => $v) {
switch ($v['title']) {
case 'Recently Sold':
$newArray[0] = $v;
break;
case 'Auctions':
$newArray[1] = $v;
break;
case 'Classifieds':
$newArray[2] = $v;
break;
}
}
ksort($newArray);
$this->_tpl_vars['boxes'] = $newArray;
{/php}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP