News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Getting the first post message text issue

Started by MobileCS, June 16, 2016, 02:21:46 PM

Previous topic - Next topic

MobileCS

I'm trying to get the text from the first post of a topic - and use that information in the index.template.php file.

The code below works, but when I use it, the actual first post disappears on the topic page itself.

Any ideas what I am doing wrong?

$first_msg = $context['get_message']();
$first_msg = $first_msg['body'];

MobileCS

Anyone?

I just don't understand why adding those 2 lines to index.template.php (and nothing else), removes the first post from the thread.

Does something need to be reset after calling "$context['get_message']()" ?

forumfan32

Can you show us the rest of your code please? My feeling is that something in your code is interfering with it.

MobileCS

There is no other code. When I add just those 2 lines to the index.template.php file, the first post of each thread disappears.

Feel free to try it out yourself.

Shambles

$context['get_message']() seems to be 'called' within Display.template.php and seems to functionally return the message list under iteration. As such, you have effectively made the first call within index.template.php, meaning latter calls within Display.template.php start at the 2nd post.

That's my guess.

As for resetting it, try calling prepareDisplayContext(true); after your initial call.

$first_msg = $context['get_message']();
$first_msg = $first_msg['body'];
prepareDisplayContext(true);


All this is just guesswork on my behalf, looking at the source code.

MobileCS

Thank you, prepareDisplayContext(true) solved the issue.

Advertisement: