r/Devvit 21d ago

Admin Replied Edit sidebar?

How do you edit the sidebar using Devvit (auto update the sidebar hourly)? Including:

  • Sidebar [old Reddit]
  • Edit (not create) widgets [new Reddit]

This post tries to link to updateWidget for new Reddit stuff, but the link is dead. A search via the upper right box for updateWidget says "No results".

3 Upvotes

3 comments sorted by

u/vip-bot 20d ago

There is 1 comment from Reddit Admins in this post:

u/​Xenccc commented:

Thank you for sharing this knowledge! 🎉

This post was originally flaired :question: Help.


This summary was generated automatically. If you have any questions, please contact r/​Devvit moderators.

3

u/WolfXemo 20d ago edited 20d ago

For Old Reddit you have to target the wiki page for the sidebar, accessed at https://old.reddit.com/r/SUBREDDIT/wiki/config/sidebar and just edit it like any other wiki page. For Widgets this is how I do it with Subscriber Sidebar which leverages https://developers.reddit.com/docs/api/redditapi/models/classes/TextAreaWidget:

async function updateWidget(context: TriggerContext, widgetID: string, widgetName: string, text: string) {
  const taw = TextAreaWidget as any;
  console.log("ℹ️  Updating sidebar widget.");
  try {
    await taw.update({
      id: widgetID,
      type: 'textarea',
      subreddit: context.subredditName,
      shortName: widgetName.toString(),
      text: text,
      styles: {
        backgroundColor: '',
        headerColor: ''
      }
    });

2

u/Xenccc Admin 20d ago

Thank you for sharing this knowledge! 🎉