Support and Documentation

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.png

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 { 1

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

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

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

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

        page.writeStart("div", 4
                "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) { 5
                    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 */
    }
}

1

Declares a class that extends from ProfilePanelTab—the class that outputs to a custom profile widget.

2

Overrides the method writeHtml, which directs output to the custom tab.

3

Retrieves the current user's 10 most recently published articles.

4

Creates the new tab with the label My Articles. Any nested page.write statements write to this tab.

5

Loops through the found articles and output the headline and date published for each.

custom-profile-tab.png