example/best practice for managing a list of strings
-
my plugin works off an array of urls.
seems easy to list the things IN the array..
not as easy to add or remove
anyone have any examples or pointers
I guess you have a separate entry field, and push 'add'
and a checkbox to select and then deletevs one big entryfield edit box, which is easy but dangerous..
i guess manage categories is similar.
-
for followup
for add & delete, I just use jQuery to manipulate the dom form entries
for save also jQuery to get the content of items in the form, and then settings.save. which informs the operational side to reload the list
it's only for admin users.
-
While you seem to have sorted it out, for future reference for anyone who finds this thread, if what you need is just managing a list in plugin settings and can handle it being an array of objects, the easiest way is to use the
sorted-list
field type, as seen in the plugin @baris mentioned, though it's even in the quickstart plugin:
https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/static/templates/admin/plugins/quickstart.tplJust create a div with
data-type="sorted-list"
anddata-sorted-list="your-setting-hash"
, then give it paths to two templates:data-item-template
which determines how each item is displayed. You should probably add two buttons here - one withdata-type="edit"
and one withdata-type="remove"
data-form-template
which will be displayed as a modal when creating a new item or editing an existing one.
Inside the original div add something like
ul
withdata-type="list"
where the items will be displayed and finally add a button withdata-type="add"
if you need to create new elements.Though as I mentioned I don't think you can manage an array of strings that way - only objects (so something like
[{value: "text1"}, {value: "text2"}]
would be the closest to an array of strings). But you can quite easily map it to a format you need - and if you wanted to have objects anyway it works great. -
@oplik0 where is the doc on data-type=???
sorted-list and what other types are supported?
( I don't want them sorted, anyhow)certainly in an objects case the modal entry form dialog would be useful.
but I don't find any doc on how do do most of the template stuff..
OHHHHH it uses HTML COMMENTS as loop control features? over some hidden connection to some css CLASS? what?!
when you can create new elements and behaviours in just about any runtime.
and it uses a file type which COULD be a link to it's format
but doesn't appear in any search results or known registration of same.
don't tell me what YOU know, take me thru the doc from creating a plugin to the linked doc of each conceptual element.
-
@sdetweil
There is documentation on how templates work in the benchpress repository - that is the templating engine NodeBB uses: https://github.com/benchpressjs/benchpressjs/tree/master/docsThere is a link to the engine in getting started development docs (https://docs.nodebb.org/development/) but I admit that it's not intuitive.
The documentation for working with included helpers and client-side modules is basically nonexistent though, I mostly just look at other plugins (quickstart is a good reference for common use cases) and ultimately just look at the code. For the included setting types you can see it here: https://github.com/NodeBB/NodeBB/tree/master/public/src/modules/settings