Not a bug Template error: Template error: Illegal string offset 'node_id'

Case

Well-known member
Affected version
2.0.1
Unsure if this is a bug.

I'm using the code @Chris D recommended here in my thread_list_macros template.

When I use the New Threads Widget on the homepage of my site to display a list of threads, I get the following server error - which I assume is related to the code I've added above?

Code:
Server error log
[LIST]
[*]ErrorException: Template error: Illegal string offset 'node_id'
[*]internal_data/code_cache/templates/l1/s24/public/thread_list_macros.php:302
[*]Generated by: Case
[*]1 Feb 2018 at 8:53 AM
[/LIST]
Stack trace
#0 internal_data/code_cache/templates/l1/s24/public/thread_list_macros.php(302): XF\Template\Templater->handleTemplateError(2, 'Illegal string ...', '/srv/users/serv...', 302, Array)
#1 src/XF/Template/Templater.php(643): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array, Array)
#2 internal_data/code_cache/templates/l1/s24/public/widget_new_posts.php(28): XF\Template\Templater->callMacro('thread_list_mac...', 'item', Array, Array)
#3 src/XF/Template/Templater.php(1230): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#4 src/XF/Widget/WidgetRenderer.php(62): XF\Template\Templater->renderTemplate('widget_new_post...', Array)
#5 src/XF/Widget/WidgetRenderer.php(67): XF\Widget\WidgetRenderer->render()
#6 internal_data/code_cache/templates/l1/s24/public/_widget_home_whats_new_tab.php(37): XF\Widget\WidgetRenderer->__toString()
#7 src/XF/Template/Templater.php(1230): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#8 src/XF/Widget/Html.php(16): XF\Template\Templater->renderTemplate('_widget_home_wh...', Array)
#9 src/XF/Template/Templater.php(1506): XF\Widget\Html->render()
#10 internal_data/code_cache/templates/l1/s24/public/forum_overview_wrapper.php(7): XF\Template\Templater->widgetPosition('forum_overview_...', Array)
#11 src/XF/Template/Templater.php(1230): XF\Template\Templater->{closure}(Object(XF\Template\Templater), Array)
#12 src/XF/Template/Templater.php(796): XF\Template\Templater->renderTemplate('forum_overview_...', Array, false)
#13 src/XF/Template/Templater.php(1286): XF\Template\Templater->applyWrappedTemplate('\n\n\n\n\n\t\n\t\n\t\n\t\t\n\t...')
#14 src/XF/Template/Template.php(24): XF\Template\Templater->renderTemplate('forum_list', Array)
#15 src/XF/Mvc/Renderer/Html.php(48): XF\Template\Template->render()
#16 src/XF/Mvc/Dispatcher.php(332): XF\Mvc\Renderer\Html->renderView('XF:Forum\\Listin...', 'public:forum_li...', Array)
#17 src/XF/Mvc/Dispatcher.php(303): XF\Mvc\Dispatcher->renderView(Object(XF\Mvc\Renderer\Html), Object(XF\Mvc\Reply\View))
#18 src/XF/Mvc/Dispatcher.php(44): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#19 src/XF/App.php(1880): XF\Mvc\Dispatcher->run()
#20 src/XF.php(328): XF\App->run()
#21 index.php(13): XF::runApp('XF\\Pub\\App')
#22 {main}
Request state
array(4) {
  ["url"] => string(8) "/forum2/"
  ["referrer"] => string(65) "https://www.<removed>.co.uk/forum/forums/off-topic.34/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
 
Which version of the code are you using?
Code:
{{ ($forum.node_id == 2 AND $thread.reply_count > 1) ? 'extra-class' : '' }}
Or:
Code:
{{ ($thread.node_id == 2 AND $thread.reply_count > 1) ? 'extra-class' : '' }}
I touched on it in the other thread that $forum isn't always passed into the macro, so there will be times where it is an empty string, which would certainly account for the error. You'd need to use the example from the second code block above. $thread is always passed into the macro and it should always contain a node_id value.
 
Which version of the code are you using?
Code:
{{ ($forum.node_id == 2 AND $thread.reply_count > 1) ? 'extra-class' : '' }}
Or:
Code:
{{ ($thread.node_id == 2 AND $thread.reply_count > 1) ? 'extra-class' : '' }}
I touched on it in the other thread that $forum isn't always passed into the macro, so there will be times where it is an empty string, which would certainly account for the error. You'd need to use the example from the second code block above. $thread is always passed into the macro and it should always contain a node_id value.

I'm getting the same thing on the new page when trying to use this (trying both $thread and $forum).

Code:
{{ $forum.Node.parent_node_id == '20' ? ' classified_ad' : '' }}

Bummer, cause adding that class to threads within that category is exactly what I needed to do. Any ideas?
 
Top Bottom