Plugins developer documentation - DRAFT #1359
Replies: 3 comments
-
Great start, thanks! For the Here is a small submission for improving section Back-end API allows plugins to:
To check if it works, you can add the following snippet to your plugin:
This is adapted from code in one of my private plugins. I like the root files option, because the default options for read and create file are different. I have always been a bit curious why the read and create do not use the same location. Lastly, I am not sure what the And would you be open to adding a debugging section? This is the section from my notes:
Codium and VS Code config
-----------------------------------------
This is the config I am using to launch Publii. Simply place this Use the If you want to use Chromium, open the inspect tab at
Other IDEsIt does not matter which IDE you use. Check how to create a new debug configuration for your IDE and then add the Cheers! |
Beta Was this translation helpful? Give feedback.
-
This is great work! It gives Publii a lot of power. I've made my first plugin for internal use. It's awesome! |
Beta Was this translation helpful? Give feedback.
-
@dziudek, @WishesofHue (or anyone...) - I really need to know how validation and error messaging works when creating a plugin. How can I communicate back to the user that a validation of their input in a plugin failed. I have the following test code, but I lack documentation on this functionality. Any assistance would be awesome. This is what I tried. I am hoping it is close, but I know it does not work.
Also - while we are on the subject - how can I echo back a value being manipulated before saving a config in the |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I know that many people have been asking for documentation for plugins, and due to a heavy workload, I haven't had the time to fully complete it. Therefore, I decided to share what I have ready, because I believe it will make it easier for many people to work on their own plugins for Publii.
Please remember that until version 1.0 of Publii, this documentation may undergo significant modifications, just like the plugin API itself. I will also try to update this post to include information about changes coming in the next versions of Publii.
I am aware that at the moment this documentation may seem quite succinct, but I simply have many other high-priority tasks queued up. I will try to improve it, and when it is fully ready - it will be moved to the official Publii documentation. Please treat this post as a draft of the final documentation.
Document due its length is currently in progress - it will be updated in next few weeks - I will add a notice below when it will be completely migrated from my notes.
History
11.2.2024 - initial work with the document
15.8.2024 - added changes regarding pages support from Publii v.0.46
Table of Contents
@plugins
global variablePlugin structure
Every plugin should contain at least:
main.js file
Example plugin file:
To interact with the website code, plugin should use at least one of the
addInsertions
,addModifiers
oraddEvents
methods.plugin.json file
Example file:
[WIP]
If plugin has empty
config
then there will be a message about lack of available options. If plugin uses flagusePluginSettingsView
and theconfig
is empty, then there is no switcher for additional settings.name
- plugin namedescription
- plugin descriptionlicense
- plugin licenseauthor
- plugin authorversion
- plugin versionscope
- scope of the plugin work. Currently the only available issite
but in the future we will addapp
andblock
.minimumPubliiVersion
- minimum required Publii versionusePluginSettingsView
- (true|false) - specifies if the plugin has custom settings fielduseCustomCssForOptions
- (true|false) - specifies if the plugin loads under their settings custom CSS from theplugin-options.css
fileassets
- addional plugin assets which are copied during rendering (as list in thefront
field)settingsDisplay
- the way of display settings:fieldsets
(default) - field groups,tabs
- groups displayed as tabstabsTitle
- title of the fieldset around tabs (use whensettingsDisplay
=tabs
)config
- plugin settings - works in the same way as in themesmessageInOption
- message displayed over options with two fields:type
- available:info
oralert
text
- message to displayrequiredFeatures
- you can specify a message that the theme must support specific insertions for proper work with plugin. Currently available options:previewNotRequired
- if set totrue
then the preview button is hidden under plugin settingsInteract with website code
There are currently three ways to change website output using plugins:
Insertions
publiiHead
- paramrenderer
<head>
section where{{publiiHead}}
is usedpubliiFooter
- paramrenderer
{{publiiFooter}}
is usedcustomHTML.*
- paramsrenderer
,context
customHTML.afterPost
customHeadCode
- paramsrenderer
,context
{{{@headCustomCode}}}
customBodyCode
- paramsrenderer
,context
{{{@bodyCustomCode}}}
customCommentsCode
- paramsrenderer
,context
{{{@commentsCustomCode}}}
customFooterCode
- paramsrenderer
,context
{{{@footerCustomCode}}}
(usually added before{{{publiiFooter}}}
customSocialSharing
- paramsrenderer
,context
{{{@customSocialSharing}}}
Example
Modifiers
postTitle
- paramsrenderer, title
,params.postData
postText
- paramsrenderer
,text
,params.postData
postExcerpt
- paramsrenderer
,excerpt
,params.postData
pageTitle
- paramsrenderer, title
,params.pageData
pageText
- paramsrenderer
,text
,params.pageData
pageExcerpt
- paramsrenderer
,excerpt
,params.pageData
jsonLD
- paramsrenderer
,jsonLD
contentStructure
- paramsrenderer
,contentStructure
globalContext
- paramsrenderer
,globalContext
postItemData
- paramsrenderer
,postData
pageItemData
- paramsrenderer
,pageData
tagItemData
- paramsrenderer
,tagData
authorItemData
- paramsrenderer
,authorData
featuredImageItemData
- paramsrenderer
,imageData
,type
,cacheItemType
socialMetaTags
- paramsrenderer
,socialMetaTagsHTML
menuStructure
- paramsrenderer
,menuStructure
unassignedMenuStructure
- paramsrenderer
,unassignedMenuStructure
htmlOutput
- paramsrenderer
,htmlCode
,globalContext
,context
feedXmlOutput
- paramsrenderer
,xmlCode
,context
feedJsonOutput
- paramsrenderer
,jsonCode
,context
customHTML.*
- paramsrenderer
,code
,context
[WIP] Example
Events
beforeRender
- paramrenderer
afterRender
- paramrenderer
[WIP] Example
...
[WIP] Custom settings view
...
[WIP] Settings management
...
[WIP] Settings API
Files from upload files controls are uploaded to
/media/plugins/PLUGIN_SLUG/
directory and are copied during deployment[WIP] Back-end API
Back-end API allows plugins to:
/config/plugins/PLUGIN_SLUG/
or root directory/media/plugins/PLUGIN_SLUG/
or root directoryreadFile(fileName, pluginInstance)
Returns value from
/input/config/plugins/PLUGIN_SLUG/
orundefined
if the file not exists. If you use[ROOT-FILES]
as a prefix of filename, you can access files from theinput/root-files
[WIP] Example
...
createFile(fileName, fileContent, pluginInstance)
Saves file with provided
fileName
andfileContent
- you can use[ROOT-FILES]
to save files underinput/root-files
.Returns:
{ status: 'FILE_SAVED' }
- on success{ status: 'FILE_NOT_SAVED' }
- on fail[WIP] Example
...
@plugins
global variableUnder themes there is a new global variable
@plugins
- which allow themes developers to chech if specific plugin is enabled and to check the plugin settings.It is stored as object:
An example of use - you can check if the social sharing plugin is enabled and the use
{{{@customSocialSharing}}}
code instead of{{> share-buttons}}
partial:Beta Was this translation helpful? Give feedback.
All reactions