View Single Post
  #8  
Old 03-07-2009, 02:36 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: extra fields, assigning a variable, using more than one extra field

No problem - I tend to make use of the extra fields frequently - so I want to try and understand them as well.

I did try to set smarty variables in nested templates - and I can confirm that what you state is correct. I guess the compiler considers those variables local and does not pass them back to the calling template (surprisingly to me too).

Your other option is to set the variables in the php - then they are available to you. (This is essentially the same as looping using the existing extra_fields array in the template - except this sets the variables in php).

(This is thoroughly untested) :

In modules/Extra_Fields/extra_fields.php

Code:
if (!empty($extra_fields)) { foreach ($extra_fields as $ef_k=>$ef_v) { if ($ef_v['field'] == "Ingredients") {$ingredients_from_php = $ef_v['field_value'];} if ($ef_v['field'] == "videocontent") {$videocontent_from_php = $ef_v['field_value'];} } } ... $smarty->assign("ingredients_from_php", $ingredients_from_php); $smarty->assign("videocontent_from_php", $videocontent_from_php);

Or - you could stick them in another array where the key is the field name:
Code:
if (!empty($extra_fields)) { foreach ($extra_fields as $ef_k=>$ef_v) { if ($ef_v['field'] == "Ingredients") {$my_display_ef['Ingredients'] = $ef_v['field_value'];} if ($ef_v['field'] == "videocontent") {$my_display_ef['$videocontent'] = $ef_v['field_value'];} } } ... $smarty->assign("my_display_ef", $my_display_ef);

Then in the template:

Code:
php array ingred: <b>{$my_display_ef.Ingredients}</b><br /> php array videocontent: <b>{$my_display_ef.videocontent}</b><br />
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote