In Open CSP 2.0 the default sidebar was added, this allows you to have sidebars without having to create custom sidebar templates for each class definition. There are some customization options built into the default sidebar as well. It is recommended to use these customization options when possible and to only create fully custom sidebar templates when absolutely necessary, as the fully custom sidebar templates require a lot more maintenance work when for example some parserfunctions get deprecated. This document describes the various customization options.
Parameters and formfield/display templates
- Edit parameters on a class definition page, to configure what will show up on your sidebar.
- Note that the parameter configuration is also used for setting properties, but you can use "(none)" as property name value if you don't want to set a property.
- Only the "parameter name" field is required. When you only fill this, you will get default text fields in the sidebars.
- Choose a displayTemplate to configure how a parameter is diaplayed in the view tab of the default sidebar.
- Choose a formfieldTemplate to coinfigure what type of form field is used in the edit tab of the default sidebar.
- DisplayTemplate and formfieldTemplate can both be set to "(none)" to not have a parameter show up in respectively the view and edit tabs of the default sidebar.
Custom formfield/display templates
- It is possible to add custom template names in the displayTemplate and formfieldTemplate fields.
- All fields that are filled for a parameter will be passed to the templates so they can be accessed through template parameters there. For example you can use {{{allowedValues|}}} in a formfieldTemplate. It might be useful to look at the csp-data slot of the class definition to see all of the parameters.
- The values of parameters on a content page are also passed to the display/formfield templates as the "value" parameter.
- In a display/formfield templates you cannot access values of other parameters directly, but you can do this by using {{#invoke:CspFunctions|getParentArgs|$pageData}}, which will return the $pageData parameter that is used in Template:Csp default sidebar (and contains an ArrayFunctions export with slotdata of the page).
- It is possible to add fields to the json data in the csp-data slot that cannot be filled through the parameters form. For example CSP 1.8.0 does not yet include the option to specify a placeholder for your formfields, but you can add placeholder to the json data and then use {{{placeholder|}}} in a custom formfieldTemplate.
Custom sidebar template where you are adding to the default sidebar
In many cases you won't necessarily want to replace the default sidebar, but you may want to add another card above or below it with additional functionality. It is possible to use the default sidebar within a custom sidebar template. For example like the following code snippet:
{{Csp default sidebar
|$pageData={{{$pageData|}}}
|$classData={{{$classData|}}}
}}
{{Csp sidebar tabs
|id=another-card
|canEdit=yes
|closeButton=
|title=Another card
|subTitle=Below the default sidebar
|view=<div class="card-body">viewtab content</div>
|edit=<div class="card-body">edittab content</div>
}}
Fully custom sidebar template
In a fully custom sidebar template you can do anything you want. You will still get the $pageData and $classData parameters passed to this template so you can use those. The following is an example of custom sidebar code that will produce a sidebar similar to the default one, perhaps this will give you some ideas for what's possible:
<div class="tab-content"><!-- --><input type="radio" id="sidebar-view" name="toggle-sidebar" checked="checked" class="d-none sidebar-view" /><!-- --><div class="card sidebar-view-tab"> <div class="card-header">{{#ifeq:{{#ifingroup:user |{{#if:{{#urlget:veaction}}{{#urlget:action}}||yes}} }}|yes |<span style="float:right"><label for="sidebar-edit" class="btn btn-secondary">Edit</label></span>}} <b class="d-block">{{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Class|_text}}</b> {{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Title|_text}} </div><!-- end of .card-header --> <div class="card-body"> {{Sidebar item |Label=Title |Value={{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Title |_text}} }}{{Sidebar item |Label=TextInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TextInput |_text}} }}{{Sidebar item |Label=TokenInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TokenInput |_text}} }}{{Sidebar item |Label=AskTokenInput |Value={{#af_join:{{#af_map:{{#af_split:{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|AskTokenInput |_text}}|,}}|@@|[[{{{@@}}}|{{#show:{{{@@}}}|?Title}}]]}}|<br>}} }}{{Test date display |Name=DateInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|DateInput |_text}} }} {{Sidebar item |Label=DateInputTwo |Value={{#if:{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|DateInputTwo |_text}} |{{#time: j M Y H:i |{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|DateInputTwo |_text}} }} }} }}{{Sidebar item |Label=TextInputTwo |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TextInputTwo |_text}} }}{{Sidebar item |Label=CheckboxInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|CheckboxInput |_text}} }}{{Sidebar item |Label=TextAreaInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TextAreaInput |_text}} }}{{Sidebar item |Label=NumberInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|NumberInput |_text}} }}{{Sidebar item |Label=SelectInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|SelectInput |_text}} }}{{Sidebar item |Label=TokenMultipleInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TokenMultipleInput |_text}} }}{{Sidebar item |Label=Rob parameter |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|Rob parameter |_text}} }}<!-- --></div><!-- end of .card-body --> </div><!-- end of .card -->{{#ifeq:{{#ifingroup:user |{{#if:{{#urlget:veaction}}{{#urlget:action}}||yes}} }}|yes |<!-- --><input type="radio" id="sidebar-edit" name="toggle-sidebar" class="d-none sidebar-edit" /><!-- --><div class="card sidebar-edit-tab"><!-- --><div class="card-header"><span style="float:right"><label for="sidebar-view" class="btn btn-secondary" >Close</label></span> <b class="d-block">{{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Class|_text}}</b> {{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Title|_text}} </div><!-- end of .card-header --> <div class="card-body"> <form><!-- // _edits: no edit when formfieldType is set to "(none)" --><_edit target="{{PAGEID}}" template="Base properties" formfield="Title" mwslot="csp-base-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TextInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TokenInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="AskTokenInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="DateInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="DateInputTwo" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TextInputTwo" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="CheckboxInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TextAreaInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="NumberInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="SelectInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TokenMultipleInput" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="TestNoDisplay" mwslot="csp-class-props" /> <_edit target="{{PAGEID}}" template="Csp class properties" formfield="Rob parameter" mwslot="csp-class-props" /> <!-- end of _edits // form fields -->{{Sidebar item |Label=Title |Value=<input type="text" name="Title" class="form-control" required="required" value="{{#af_get:{{{$pageData}}}|csp-base-props|Base properties|1|Title|_text}}" /> }} {{Sidebar item |Label=TextInput |Value=<input type="text" name="TextInput" class="form-control" required="required" value="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TextInput|_text}}" /> }} {{Sidebar item |Label=TokenInput |Value=<_token id="token-{{lc:{{anchorencode:TokenInput}} }}" name="TokenInput[]" class="form-control" allowclear selected="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TokenInput|_text}}" options="Ay,Bee,Cee" /> }} {{Sidebar item |Label=AskTokenInput |Value=<_token id="token-{{lc:{{anchorencode:AskTokenInput}} }}" name="AskTokenInput[]" class="form-control" required="required" multiple="multiple" input-length-trigger="1" query="[[Class::+]][[Title::!!!]](limit=999)(returntext=Title)" > {{#af_join:{{#af_map:{{#af_split:{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|AskTokenInput|_text}} }} |$value|<option value="{{{$value}}}" selected="selected">{{#show:{{{$value}}}|?Title}}</option>}}|\n}} </_token> }} {{Test date formfield |Name=DateInput |Value={{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|DateInput|_text}} }}{{Sidebar item |Label=DateInputTwo |Value=<input type="datetime-local" name="DateInputTwo" class="form-control" value="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|DateInputTwo|_text}}" /> }} <div class='alert alert-danger'>No template defined in parameter definitions</div>{{Sidebar item |Label=<label for="checkbox-{{lc:{{anchorencode:CheckboxInput}} }}" >CheckboxInput</label> |Value=<input type="hidden" name="CheckboxInput" value="" /> <input type="checkbox" id="checkbox-{{lc:{{anchorencode:CheckboxInput}} }}" name="CheckboxInput" value="Yes" checked="{{#ifeq:{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|CheckboxInput|_text}} |Yes|checked}}" /> }} {{Sidebar item |Label=TextAreaInput |Value=<input type="textarea" name="TextAreaInput" class="form-control" >{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TextAreaInput|_text}}</input> }} {{Sidebar item |Label=NumberInput |Value=<input type="number" name="NumberInput" class="form-control" value="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|NumberInput|_text}}" /> }} {{Sidebar item |Label=SelectInput |Value=<select name="SelectInput" class="form-control" allowclear selected="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|SelectInput|_text}}" options="Alpha,Bravo,Charlie" /> }} {{Sidebar item |Label=TokenMultipleInput |Value=<_token id="token-{{lc:{{anchorencode:TokenMultipleInput}} }}" name="TokenMultipleInput[]" class="form-control" multiple="multiple" selected="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TokenMultipleInput|_text}}" options="Alpha,Bravo,Charlie" /> }} {{Sidebar item |Label=TestNoDisplay |Value=<input type="text" name="TestNoDisplay" class="form-control" value="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|TestNoDisplay|_text}}" /> }} {{Sidebar item |Label=Rob parameter |Value=<input type="number" name="Rob parameter" class="form-control" value="{{#af_get:{{{$pageData}}}|csp-class-props|Csp class properties|1|Rob parameter|_text}}" /> }} <!-- --><div class="text-right"> <label for="sidebar-view" class="btn btn-secondary">Close</label> <input type="submit" value="Save" class="btn btn-primary" /> </div> </form> </div><!-- end of .card-body --> </div><!-- end of .card --> |}}<!-- end of #ifeq @allow sidebar edit == yes --> </div>