Help Center

Find answers or browse our knowledge base.

post_to_feed

πŸ“° Hook: post_to_feed

The post_to_feed filter hook lets addons customize how posts appear in the Sngine newsfeed. It is triggered every time a feed post is prepared for rendering.

πŸ“Œ Signature

apply_filters('post_to_feed', $value, $post);
  • $value → array of fields passed to feed templates
  • $post → raw feed post data from database
  • Must return the modified $value

πŸ“‚ Template Dependencies

  • Addonid/tabs/feed_story.tpl → renders the main storyline text (headline of the post)
  • Addonid/tabs/feed_content.tpl → renders body, attachments, or any custom block your addon injects

That means if your addon injects $value['story'], it will be displayed inside feed_story.tpl. If your addon injects custom keys like $value['book_custom'], they can be rendered in feed_content.tpl.

βœ… Example: Books Addon

Hook file: modules/books/hooks/post_to_feed.php


return function($value, $post) {
    if ($post['post_type'] === 'book') {
        // Storyline for feed_story.tpl
        $value['story'] = $post['user_firstname'] . " is reading πŸ“–";

        // Extra block for feed_content.tpl
        $value['book_custom'] = [
            'title' => $post['book_title'],
            'url'   => $post['book_url']
        ];
    }
    return $value;
};

feed_story.tpl


{if $post.post_type == "book"}
  Jane is reading  {$post.story}
{/if}
 

feed_content.tpl


{if isset($post.book_custom)}
 

πŸ”Ž How It Works

  1. Your addon’s hook modifies the $value array.
  2. Sngine passes that array into the feed templates.
  3. feed_story.tpl shows the short text (headline).
  4. feed_content.tpl shows extended details or attachments.

πŸ’‘ Best Practices

  • Always check $post['post_type'] before modifying output.
  • Use $value['story'] for human-readable text (the "Jane is reading a book" headline).
  • Use custom array keys for extra data (e.g. book_custom, badge_custom).
  • Keep template logic minimal — put conditions and DB queries inside the hook, not in TPL.
Was this answer helpful?
You must login to vote.
0 found this helpful, 0 did not
Thank you for your feedback!

Related Articles