<p>By default each model can have child pages. This is what enables the
hierarchical structure of the Lektor database. Children are configured
together with a model that encloses it. This is typically called the
“collection model”. For instance you can have a collection model called
<code>pages</code> which is the parent to a few <code>page</code> children.</p>
<h2id="child-configuration">Child Configuration</h2><p>Most configuration related to child pages goes into <code>[children]</code>. It
configures how children of the model should be handled. In particular it
controls if a page can have children to begin with, if the children can be of
any format or have to match specific models and more.</p>
<p>Here are the most important options below <code>[children]</code>:</p>
<ul>
<li><code>enabled</code>: this can enable or disable children. The default is that a
page can have children.</li>
<li><code>slug_format</code>: this key controls the URL key for children. By default
the URL key is the ID of the page. However in some cases you might
want to change that. For instance blog-posts might want to pull in
parts of the date into the URL. This is a template expression.</li>
<li><code>model</code>: if this is set to a string, then all children are automatically
forced to the same model and the UI will not give a way to select a
model when creating a new child page. This allows specific parts of
the website to use the correct models automatically. For instance you
can force all pages below <code>/projects</code> to use the <code>project</code> model.</li>
<li><code>order_by</code>: a comma separated list of fields that indicate the default
sort order. If a field is prefixed with a minus sign, the order is
inversed.</li>
<li><code>replaced_with</code>: this allows a page to simulate that it has children
when it really has not. This can be a query expression and the result
is then used as the children of the model. This for instance can be
used to implement categories with filtering.</li>
<li><code>hidden</code>: if this is set it can override the parent's hidden flag for
all children. This is particularly useful if you want to have a folder
for error pages or other special pages where the parent itself should not
be rendered but all children are. The default is not set.</li>
</ul>
<divclass="admonition admonition-info"><p>The <code>hidden</code> flag was added in Lektor 2.0</p></div><h2id="child-slug-behavior">Child Slug Behavior</h2><p>Slugs are the URL paths or more correctly: parts of it. The URL paths
always are the concatenation from the parent's page URL path plus the
children's slug. If not configured the default slug of children is the
page's <code>_id</code>. A slug can contain slashes to navigate into folders. This
also allows pages to overlap into other pages. For instance if you have
a model called <code>categories</code> which is used by a folder named <code>categories/</code>,
that folder could set the <code>_slug</code> to <code>blog/categories</code> and then the URL
for categories would be <code>blog/categories/example</code> instead of
<code>categories/example</code>.</p>
<p>The default slug can be changed with the <code>slug_format</code> parameter in the
<code>[children]</code> section which can be a template expression. For instance a
common way to format slugs would be to include some date components. What's
important about this is that the slug expression must not fail even if fields
are empty! This is necessary because new pages will start out with the
fields not being filled in.</p>
<p>This for instance includes a date in the URL if set:</p>
Please enable JavaScript to view the <ahref="https://disqus.com/?ref_noscript"
rel="nofollow">comments powered by Disqus.</a>
</noscript>
</div>
</div>
</div>
</div>
</div>
<divclass="bottomsummary">
<divclass="container">
</div>
</div>
<footer>
<divclass="container">
<divclass="row">
<divclass="col-sm-4 icon-bar">
<ahref="https://github.com/lektor/lektor/"title="Lektor on GitHub"
><iclass="fa fa-github"></i></a>
<ahref="https://github.com/lektor/lektor/issues/"title="Report Issues for Lektor"
><iclass="fa fa-bug"></i></a>
<ahref="https://twitter.com/getlektor"title="Find Lektor on Twitter"
><iclass="fa fa-twitter"></i></a>
<ahref="https://gitter.im/lektor/lektor"title="Chat on Gitter"
><iclass="fa fa-comment"></i></a>
<ahref="https://github.com/lektor/lektor-website/tree/master/content/docs/models/children/contents.lr"title="View source for this page"><iclass="fa fa-code"></i></a>