Extending schema for topics/posts
-
Is there a recommended way to extend the schema of an object in nodeBB? As an example, lets say I want to store a value for a header image for a topic as a custom attribute, how would I go about adding that attribute to the topic without having to modify the core code?
-
Since there is no fixed schema, you can add custom fields to topics/posts easily. For example in a plugin you can just do :
const topics = require.main.require('./src/topics'); await topics.setTopicField(someTopicId, 'headerImage', 'https://urltoyourimage');
Then
headerImage
will be part of that topic and become available for use intopic.tpl
ie:<!-- inside topic.tpl --> {{{ if headerImage }}} <img src="{headerImage}" /> {{{ end }}}
Copyright © 2024 NodeBB | Contributors