Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets with a context #5633

Open
NicolasSiver opened this issue Apr 27, 2017 · 9 comments
Open

Widgets with a context #5633

NicolasSiver opened this issue Apr 27, 2017 · 9 comments

Comments

@NicolasSiver
Copy link

Hello, guys.

I'm exploring the idea to use widgets to inject plugin data.

Today, I'm asking plugin users to change their theme and include templates:

https://github.com/NicolasSiver/nodebb-plugin-ns-awards/tree/ea9491fd50b80fe28131c09544da1ee5a511827d#profile-template

Would be great, if we can use widgets for that (or a new entity). But it's not possible since widgets do not provide a context. For example, we could inject extra data in every post in the topic view, to accomplish it, the widget should capture post context.

If it will work with widgets, theme developers could start to provide a widget placeholders for posts, account/profile, etc.

@pitaj
Copy link
Contributor

pitaj commented Apr 27, 2017

I'm not sure what you're asking. Are you asking for widget templates to have have access to the general surrounding page template data?

@NicolasSiver
Copy link
Author

I'm asking for the context when widget data is requested. Or it could be a different abstraction if feature-request does not align well with a widget design.

For example, if widget is defined in the post template, it will provide post context with every request for render.

@barisusakli
Copy link
Member

This might be possible by passing ajaxify.data to https://github.com/NodeBB/NodeBB/blob/master/public/src/widgets.js#L45. Give that a shot and see if you can use the page data in your widget.

@pitaj pitaj added the question label Apr 27, 2017
@NicolasSiver
Copy link
Author

If widgets implemented in a way, that all DOM elements are scanned on the page, then it's possible to accomplish, but it will require some convention.

Just an example for post.tpl

<div class="post-user">
        <div class="icon">
            <a href="<!-- IF posts.user.userslug -->{config.relative_path}/user/{posts.user.userslug}<!-- ELSE -->#<!-- ENDIF posts.user.userslug -->">
                <!-- IF posts.user.picture -->
                <img component="user/picture" data-uid="{posts.user.uid}" src="{posts.user.picture}" align="left" itemprop="image" />
                <!-- ELSE -->
                <div component="user/picture" data-uid="{posts.user.uid}" class="user-icon" style="background-color: {posts.user.icon:bgColor};">{posts.user.icon:text}</div>
                <!-- ENDIF posts.user.picture -->
		    </a>
            <div class="status-badge {posts.user.status}" component="user/status"  title="[[global:{posts.user.status}]]"></div>
            <div class="points-badge" component="post/points" data-points="{posts.points}" data-pid="{posts.pid}"></div>
        </div>

        <div class="group-label-container">
            <div class="widgets" widget-area="post-user-card" widget-context="pid"></div>
            <!-- IMPORT partials/topic/badge.tpl -->
        </div>

where pid will require extracting data-pid value from the closest parent component to the widget definition. So the hook for the widget will have also:

{
    context: {
        pid: "80800"
    }
}

@NicolasSiver
Copy link
Author

Multiple will look like this:

<div class="widgets" widget-area="post-user-card" widget-context="pid,uid"></div>

@psychobunny
Copy link
Contributor

This might be possible by passing ajaxify.data to https://github.com/NodeBB/NodeBB/blob/master/public/src/widgets.js#L45. Give that a shot and see if you can use the page data in your widget.

I prefer this, seems to make sense. Any objection of using this instead @NicolasSiver ?

@NicolasSiver
Copy link
Author

I'm not sure ajaxify can help here.

widgets-areas

Here is an example. Let say there is a widget area in the post.
How will such widget know, what is Author ID or Post ID?

For example, filter for posts provides a context. If widgets will have same capabilities, it will be possible to make plugins without the requirement to edit templates. It will open brand new capabilities with theme creators.

@pitaj
Copy link
Contributor

pitaj commented Jun 6, 2017

I don't think it's possible to do that at the moment. This relates closely to #4728 though.

@NicolasSiver
Copy link
Author

It's a feature request. ;)
Maybe you have a better idea how to achieve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants