Brightspot CMS Developer Guide

Profile tabs


The header contains a link to display the current user’s profile in a widget. The default implementation displays two tabs in the widget: Profile and History.

Default profile tabs


You can add custom tabs to the profile widget by extending the ProfilePanelTab class. The following example creates a My Articles profile tab that lists the current user’s 10 most recently published articles.

import com.psddev.dari.util.PaginatedResult;
import content.article.Article;

public class MySummaryTab extends ProfilePanelTab { 

    @Override
    public void writeHtml(ToolPageContext page) throws IOException, ServletException { 

        UUID uuid = page.getUser().getId();

        PaginatedResult<Article> articles = Query.from(Article.class) 
                .where("cms.content.publishUser = ?", uuid)
                .sortDescending("cms.content.publishDate")
                .select(0, 10);

        List<Article> myArticles = articles.getItems();

        page.writeStart("div", 
                "class", "p-tud-lg tabbed",
                "data-tab", "My Articles");
            page.writeStart("h1");
                page.writeHtml("My Articles");
            page.writeEnd();
            page.writeStart("h2");
                page.writeHtml("The following table lists your 10 most recently published articles.");
            page.writeEnd();
            page.writeStart("table");
                page.writeStart("tr");
                    page.writeStart("th");
                        page.writeHtml("Headline");
                    page.writeEnd(); /* th */
                    page.writeStart("th");
                        page.writeHtml("Date Activity");
                    page.writeEnd(); /* th */
                page.writeEnd(); /* tr */

                for (Article article : myArticles) { 
                    page.writeStart("tr");
                        page.writeStart("td");
                            page.writeHtml(article.getHeadline());
                        page.writeEnd(); /* td */
                        page.writeStart("td");
                            page.writeHtml(article.getPublishDate());
                        page.writeEnd(); /* td */
                    page.writeEnd(); /* tr */
                }

            page.writeEnd(); /* table */
        page.writeEnd(); /* div */
    }
}
  • Declares a class that extends from ProfilePanelTab—the class that outputs to a custom profile widget.
  • Overrides the method writeHtml, which directs output to the custom tab.
  • Retrieves the current user’s 10 most recently published articles.
  • Creates the new tab with the label My Articles. Any nested page.write statements write to this tab.
  • Loops through the found articles and output the headline and date published for each.

Custom profile tab

See also:

Previous Topic
Tabs
Next Topic
Adding areas to the navigation menu
Was this topic helpful?
Thanks for your feedback.