children
The children
keyword returns the child nodes of the current node.
Note: This keyword is only available on Page Elements (DOM nodes).
You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.
The children
keyword returns the child nodes of the current node.
Note: This keyword is only available on Page Elements (DOM nodes).
The children keyword returns the child nodes of the current node.
Icon | Action |
---|---|
Clone element and all its children | |
Open Properties dialog | |
Delete element and all its children | |
Remove element and all its children | |
Open Access Control and Visibility Dialog | |
Open Edit Content Dialog | |
Open Edit Link Dialog |
${{
// fetch the templates child elements
const children = $.get('children');
// render the child elements
$.render(children);
}}
This content type must be set on template elements or content elements that are included using the built-in include() function, and on so-called Main Page Templates that use ${render(<a data-id="3230f1d81eb345c199024b82eb7c56f2" class="mention">children</a>)}
.
As defined in the DOM specification, Content Elements must not have child nodes. To be able to mix template expressions and node structures, Structr provides a block-version of Content Elements, the so-called Template Elements (). Similar to Content Elements, Template Elements support different content types and allow for template expressions. However, in contrast to Content Elements, Template Elements can have children.
We start by introducing the template element. In Structr, templates are special elements that may be inserted into a page’s DOM tree at any position. Much like a content element, a template element has a body which is rendered into the page. However, in contrast to the content element, a template element may have children in the DOM tree, which will become important later on.
Therefore, the rendering flow stops at template elements and does not render the remaining branch of the DOM tree. Instead, the template element has to explicitly invoke the rendering process for it’s child elements in the appropriate place. To accomplish this, Structr provides the children
keyword and the render() function, as shown in the example below. While this makes the configuration of template elements a bit more subtle than that of content elements, it provides much more flexibility.
Each Type contains child elements representing it’s Local Attributes, Remote Attributes, Views, Methods and Inherited Attributes. With the exception of Inherited Attributes, which are read-only, all children provide options to mange their respective content.
Finally, we create a shared component out of this template element. This allows us to include the template into every new page we create within this project, creating a skeleton for new pages that include the top navigation menu and the footer. Due to the render(<a data-id="3230f1d81eb345c199024b82eb7c56f2" class="mention">children</a>)
expression in the template body, the individual content of each new page can then be added as a child of the template in the DOM tree, allowing us to quickly create pages with the same main theme but different content.
You can create new Shared Components by dragging and dropping an element from the Pages Tree View into the drop area at the top of the Shared Components flyout. When you do that, Structr copies the source element to the Shared Components flyout and moves all its children to the new copy. The source element becomes a so-called “synced node” that relays the rendering process to the Shared Component.
Icon | Action |
---|---|
Open File’s content (and dynamic content) dialog | |
Open Properties dialog | |
Delete the File or Folder (with all it’s children) | |
Open Access Control and Visibility dialog |
<!-- Page Content-->
${render(children)}