HTML modules
Intro
Starting with v2.1.0 you can define and configure the modules available in a template using HTML markup.
For example:
<p wf-module="wfed/body_text/page_epigraph"></p>
Important:
the modules should always be in their own container, without mixing them with "static" HTML. For example:
html<!-- BAD --> <div> <p wf-module="wfed/body_text/page_epigraph"></p> <div class="static-html">HTML Content that is not a module</div> </div> <!-- GOOD --> <div> <div class="modules"> <p wf-module="wfed/body_text/page_epigraph"></p> </div> <div class="static-html">HTML Content that is not a module</div> </div>
The modules' container should always have a unique (in the current document) class associated
html<!-- BAD because the container doesn't have any class --> <div> <p wf-module="wfed/body_text/page_epigraph"></p> </div> <!-- BAD because there are two containers with the same class --> <div class="text"> <p wf-module="wfed/body_text/page_epigraph"></p> </div> <div class="text"> <p wf-module="wfed/body_text/page_epigraph"></p> </div> <!-- GOOD - the CMS uses the unique class, even though the containers share the "text" class --> <div class="text paragraphs-1"> <p wf-module="wfed/body_text/page_epigraph"></p> </div> <div class="text paragraphs-2"> <p wf-module="wfed/body_text/page_epigraph"></p> </div>
Available options, available to all modules:
wf-role
: Use in the article's template to determine the role of this module. The role can be any string. The following list of roles has a special meaning, as it is used throughout XalokNext:title
: the titlesupra
: the line above the titleepigraph
: the introductory paragraph (short description)author
: the name of the authorcategoryTitle
: the sectionsignature
: the field containing the signature (editor's name, agency)location
: the location (if available) where the news happenedimage
: the main image of the article. The image chosen in this module is used to auto-populate the image modules of page captioned modules when this article is selected in a boardimage_captioned
: use this instead of theimage
if the main image has a captionparagraph
: use this for the normal paragraph (body text)
wf-toolbar-position
: Controls the position of the toolbar with regard to the current module. Use one oftop
,left
,right
,bottom
ornone
wf-toolbar-css-class
: use<p wf-toolbar-css-class="sub"></p>
to display a thinner toolbar than the default. This class is automatically added to submodules of a compositewf-toolbar-tooltips-position
: When wf-group is used (switching modules) a tooltip is displayed if available. Put an image in__ADMIN_BUNDLE_/Resources/public/images/modules/__MODULE_ID__.png
. The name of the file is converted by replacing the '/' with double underscore. E.g.admin/composite/video_image
should have a thumbnail namedadmin__composite__video_image.png
. Possible values:top
,left
,right
,bottom
ornone
. Default equals the value ofwf-toolbar-position
wf-allow
: Available values:+-
: allow both adding another module and deleting the current module+
: allow adding modules below this one but not deleting this module-
: allow deleting this module- ``(empty string): this module is "fixed", don't allow adding any other modules nor deleting this one.
For example: in the article template, there should be only one title :
html<h1 wf-module="wfed/title/page_title" wf-allow="" />
wf-new
: This attribute's value is optional. If present, the current module will be added automatically when a new page with this template is created.For example, the page title module in the article template should always be present, add the
wf-new
module to it and set itswf-allow
attribute to an empty string:html<h1 wf-module="wfed/title/page_title" wf-allow="" wf-new />
Optionally, you can specify a number as the value, if you want the same module repeated a few times:
<p wf-module="wfed/body_text/paragraph" wf-new="3" />
wf-serializable
: Avaialble only for top level modules and only for roled modules and only for text modules (for now, at least). This attribute adds the value of the module in the serialized content of the article, allowing to import this module's value in a board module.html<!-- in article's template --> <p wf-module="wfed/body_text/block" wf-role="special-flag-of-article" wf-serializable></p> <!-- in boards's template --> <div wf-module="wfed/composite/page"> <div wf-module="wfed/body_text/block" wf-role="special-flag-of-article"> </div> </div>
wf-tab
andwf-tab-detail
html<div class="tabs"> <div class="titles"> <p wf-module="wfed/body_text/inline" wf-use-placeholder="true" wf-tab >Tab</p> </div> <div class="body"> <div wf-module="wfed/composite/page" wf-tab-detail > <div wf-module="wfed/body_text/block" wf-role="title" > </div> </div> </div>
For each module with wf-tab that is added in the
.tabs .titles
selector, it creates a different.tabs .body
selector where you can add modules to be displayed on that tabwf-required
: make the given module required (the user must fill something for this module). Enter the error message that should appear as the value of the attribute.html<p wf-module="wfed/body_text/block" wf-role="epigraph" wf-required="The epigraph is required" ></p>
Options for wfed/body_text
modules
wf-formattings
: controls what options are displayed to format the text.html<p wf-formattings="b,i,u"></p>
displays bold, italic and underline buttons
Available formattings:
b
: boldu
: underlinei
: italicol
: ordered listul
: unordered lista
: links
: strikethrough
There are also some shorthands available:
short
: bold, underline, italic, strikethrough, linklists
: ordered and unordered listsextended
: includesshort
+lists
You can combine these options in any way you want:
html<p wf-formattings="b,i,lists"></p>
wf-styles
: Displays a dropdown on the list where editors can mark selected text with given classeshtml<p wf-styles="red-text,blue-text"></p>
displays a dropdown allowing the editors to add a
<span class="red-text"></span>
(or "blue-text") around the selectionwf-use-placeholder
: Displays the module even if no text has been changed in ithtml<p wf-use-placeholder="true"></p>
Useful for modules with settings only.
wf-maxlength
: Prevent the editor from entering more than maxlength characters. A char count is displayed on the toolbar, so make sure you display the toolbar ifwf-maxlength
orwf-soft-maxlength
is setwf-soft-maxlength
: Displays an warning when the editor exceeds entering this many characters, but allows them to continue.
Options for wfed/image
modules
wf-filter
: the avalanche filter (widthxheight) of this image. The value of this option must be configured inapp/config/misc/avalanche.yml
Options for wfed/collection
modules
wf-content-type
html<div wf-module="wfed/slider/simple" wf-new> <div class="slider-pane"> <div wf-module="wfed/composite/module" wf-toolbar-position="none" wf-content-type="image" > <div class="image"> <div wf-module="wfed/image/simple" wf-filter="article_related_item" ></div> </div> <div class="caption"> <p wf-module="wfed/body_text/block"></p> </div> </div> </div> </div>
Allowed (builtin) values:
image
,video
,audio
,page
,poll
,file
,listing
There's also the special "type"none
- for sliders where the edit button should be hidden and the slides' contents should be edited manually (e.g.: a slider where each slide should have multiple boxes/articles) Addwf-content-type
to the slide's definition. This adds the "edit" button on the toolbar of the slider, allowing the editor to select multiplewf-content-type
- when the editor presses "OK", a slide for eachwf-content-type
is created and added to the slider.wf-slider-options
-> value should be a hashwf-max-items
-> value should be an string numberwf-submodule-add
-> value should be true/false; default is truewf-submodule-delete
-> value should be true/false; default is truehtml<div wf-module="wfed/slider/simple" wf-slider-options='{"perPage": "5", "slideSize": "1"}' wf-max-items="10" wf-submodule-add="false" wf-submodule-add="true" wf-new> <div class="slider-pane"> ... </div> </div>
Options for wfed/dynamic/board
module
wf-slugs
: Container forslug
elements which have at value the slugs of the included boards
<div wf-module="wfed/dynamic/board">
<wf-slugs>
<slug value="x">X</slug>
<slug value="y">Y</slug>
</wf-slugs>
</div>
Options for wfed/composite/page
module
wf-allow-edit
: Setting to show or hide the button to select an article. By default it is true - the button is shown
<div wf-module="wfed/composite/page"
wf-allow-edit="false"
>...</div>
Options for wfed/body_text/published_at
module
wf-format
: Setting to set the format in witch the date/time is displayed. Parsed with momentjs. Escaped strings should be enclosed in square brackets:[escaped string]
<div wf-module="wfed/body_text/published_at"
wf-format="[Latest published at:] HH:mm"
></div>
Options for wfed/image/picture
module
Adds a picture
tag that includes, besides the default <img>
tag, <source>
tags for different resolutions. The wf-filter
option can define multiple avalanche filters, separated by |
. The filter name can also include the max-width
, used for media query:
<picture wf-module="wfed/image/picture"
wf-filter="desktop|mobile:320|tablet:728">
</picture>
This outputs:
<picture>
<source srcset="/files/mobile/image.jpg" media="max-width: 320px" />
<source srcset="/files/tablet/image.jpg" media="max-width: 320px" />
<img src="/files/desktop/image.jpg" />
</picture>