[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [BP][FIX] Tracker item history: pre-render field values before template to...

"Bruno Kambere \(@kambereBr\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69f8c39ca36d3_3819017c5284c@gitlab-sidekiq-low-urgency-cpu-bound-v2-57846dc76f-t6dh9.mail>

Bruno Kambere pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki


Commits:
8410c98d by Bruno Kambere at 2026-05-04T18:43:10+03:00
[BP][FIX] Tracker item history: pre-render field values before template to avoid "Too late to modify headers"
---
* [FIX] Tracker item history: pre-render field values before template to avoid "Too late to modify headers"
---
* [FIX] Tracker item history: pre-render field values before template to avoid "Too late to modify headers"

See merge request tikiwiki/tiki!10052

See merge request tikiwiki/tiki!10132

- - - - -


2 changed files:

- lib/core/Services/Tracker/Controller.php
- templates/tracker/item_history.tpl


Changes:

=====================================
lib/core/Services/Tracker/Controller.php
=====================================
@@ -2400,30 +2400,51 @@ class Services_Tracker_Controller
                             ];
                         }
                     }
-                    if (TIKI_API) {
-                        $field_value = $field_option[$hist['fieldId']];
+                    // Pre-render field values here in the controller, before Smarty starts rendering the template.
+                    $field_value = $field_option[$hist['fieldId']];
+                    if (! empty($field_value['fieldId']) && $field_value['fieldId'] > 0) {
+                        $emptyTemplate = TikiLib::lib('smarty')->getEmptyInternalTemplate();
                         if (empty($diff_style)) {
-                            if (! empty($field_value['fieldId'])) {
+                            $field_value['value'] = $hist['value'];
+                            $hist['rendered_value'] = smarty_function_trackeroutput([
+                                'field' => $field_value,
+                                'list_mode' => 'csv',
+                                'history' => 'y',
+                                'item' => $item_info,
+                                'process' => 'y',
+                            ], $emptyTemplate);
+                            $field_value['value'] = $hist['new'];
+                            $hist['rendered_new'] = smarty_function_trackeroutput([
+                                'field' => $field_value,
+                                'list_mode' => 'csv',
+                                'history' => 'y',
+                                'item' => $item_info,
+                                'process' => 'y',
+                            ], $emptyTemplate);
+
+                            if (TIKI_API) {
+                                $hist['value'] = $hist['rendered_value'];
+                                $hist['new'] = $hist['rendered_new'];
                                 $field_value['value'] = $hist['value'];
-                                $hist['value'] = smarty_function_trackeroutput([
+                                $hist['rendered_value'] = smarty_function_trackeroutput([
                                     'field' => $field_value,
-                                    'list_mode' => 'csv',
+                                    'list_mode' => 'y',
                                     'history' => 'y',
                                     'item' => $item_info,
                                     'process' => 'y',
-                                ], TikiLib::lib('smarty')->getEmptyInternalTemplate());
+                                ], $emptyTemplate);
                                 $field_value['value'] = $hist['new'];
-                                $hist['new'] = smarty_function_trackeroutput([
+                                $hist['rendered_new'] = smarty_function_trackeroutput([
                                     'field' => $field_value,
-                                    'list_mode' => 'csv',
+                                    'list_mode' => 'y',
                                     'history' => 'y',
                                     'item' => $item_info,
                                     'process' => 'y',
-                                ], TikiLib::lib('smarty')->getEmptyInternalTemplate());
+                                ], $emptyTemplate);
                             }
                         } else {
                             $field_value['value'] = $hist['new'];
-                            $hist['diff'] = smarty_function_trackeroutput([
+                            $hist['rendered_diff'] = smarty_function_trackeroutput([
                                 'field' => $field_value,
                                 'list_mode' => 'y',
                                 'history' => 'y',
@@ -2431,25 +2452,11 @@ class Services_Tracker_Controller
                                 'process' => 'y',
                                 'oldValue' => $hist['value'],
                                 'diff_style' => $diff_style,
-                            ], TikiLib::lib('smarty')->getEmptyInternalTemplate());
-                        }
-                        if (! empty($field_value['fieldId'])) {
-                            $field_value['value'] = $hist['value'];
-                            $hist['rendered_value'] = smarty_function_trackeroutput([
-                                'field' => $field_value,
-                                'list_mode' => 'y',
-                                'history' => 'y',
-                                'item' => $item_info,
-                                'process' => 'y',
-                            ], TikiLib::lib('smarty')->getEmptyInternalTemplate());
-                            $field_value['value'] = $hist['new'];
-                            $hist['rendered_new'] = smarty_function_trackeroutput([
-                                'field' => $field_value,
-                                'list_mode' => 'y',
-                                'history' => 'y',
-                                'item' => $item_info,
-                                'process' => 'y',
-                            ], TikiLib::lib('smarty')->getEmptyInternalTemplate());
+                            ], $emptyTemplate);
+
+                            if (TIKI_API) {
+                                $hist['diff'] = $hist['rendered_diff'];
+                            }
                         }
                     }
                 }


=====================================
templates/tracker/item_history.tpl
=====================================
@@ -90,8 +90,8 @@
                             </td>
                             {if empty($diff_style)}
                                 {if !empty($field_value.fieldId) && $field_value.fieldId > 0}
-                                    <td class="text">{$field_value.value=$hist.value}{trackeroutput field=$field_value list_mode=csv item=$item_info history=y process=y}</td>
-                                    <td class="text">{$field_value.value=$hist.new}{trackeroutput field=$field_value list_mode=csv item=$item_info history=y process=y}</td>
+                                    <td class="text">{$hist.rendered_value}</td>
+                                    <td class="text">{$hist.rendered_new}</td>
                                 {else}
                                     <td class="text">{$hist.value|escape}</td>
                                     <td class="text">{$hist.new|escape}</td>
@@ -99,8 +99,7 @@
                             {else}
                                 <td colspan="2" class="tracker-diff {$diff_style}">
                                     {if !empty($field_value.fieldId) && $field_value.fieldId > 0}
-                                        {$field_value.value=$hist.new}
-                                        {trackeroutput field=$field_value list_mode='y' history=y item=$item_info process=y oldValue=$hist.value diff_style=$diff_style}
+                                        {$hist.rendered_diff}
                                     {else}
                                         {wikidiff object_type=direct oldver=$hist.value newver=$hist.new diff_style=$diff_style}
                                     {/if}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8410c98d68d3ff7b47974b7f93e8ed1c7eed98a7

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8410c98d68d3ff7b47974b7f93e8ed1c7eed98a7
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.