{"componentChunkName":"component---src-templates-blog-post-js","path":"/bolt-content-and-relations/","result":{"data":{"site":{"siteMetadata":{"title":"Undefined","author":"Anirudh Varma"}},"markdownRemark":{"id":"2845cef4-50a1-5080-a32e-9d14c64aebb8","excerpt":"For a recent website project, I decided to use Bolt CMS, a\nfree and open source content management system that is really powerful while\nbeing flexible and easy…","html":"<p>For a recent website project, I decided to use <a href=\"https://bolt.cm/\">Bolt CMS,</a> a\nfree and open source content management system that is really powerful while\nbeing flexible and easy to use. One concept that I really liked was that of\n<a href=\"https://docs.bolt.cm/3.4/contenttypes/intro\">ContentTypes,</a></p>\n<p>From the documentation —</p>\n<blockquote>\n<p>Most websites will also have some form of news-like items, that are shown based\non the date that they were published. Some other sites might have ‘book reviews’\nor ‘event dates’ or even completely different content. All of these different\ntypes of content are called <strong>ContentTypes</strong> in Bolt, and you can add as many\ndifferent ContentTypes as you need.\nEach ContentType is made up of <strong>Fields….</strong></p>\n</blockquote>\n<p>Our project was a dance company site, so we defined the following Content Types\n—</p>\n<ol>\n<li>Team Members.</li>\n<li>Videos</li>\n<li>Series (Collection of Videos)</li>\n</ol>\n<p>In Bolt, all contenttypes are defined in <em>contenttypes.yml</em>. Here is what a\nsample contenttype looks like —</p>\n<p>This is pretty similar to creating a database table with the fields title,\ndescription, frameUrl &#x26; type. The <em>record</em>template_ indicates the twig template\nto be used when the page for this content type is rendered.</p>\n<h2 id=\"relations\" style=\"position:relative;\"><a href=\"#relations\" aria-label=\"relations permalink\" class=\"anchor-hint before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Relations</h2>\n<p>Your database has relations, so it would be amazing if your contenttypes had\nrelations, right? Bolt supports creating Relationships between your content\ntypes and it is pretty straight forward. Here is the <em>Series</em> contenttype —</p>\n<p>Now, as I mentioned earlier. Series is a collection of Videos. The key here is\n<em>relations</em> configuration. The <em>works</em> field maps <em>series</em> to the <em>works</em> contenttype.<br> Multiple — true means that multiple *works *records can be\nassociated to one <em>series</em> record.</p>\n<h2 id=\"retrieving-and-rendering-related-records-in-templates\" style=\"position:relative;\"><a href=\"#retrieving-and-rendering-related-records-in-templates\" aria-label=\"retrieving and rendering related records in templates permalink\" class=\"anchor-hint before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Retrieving and rendering related records in templates</h2>\n<p>Here is how to list all related records in twig templates.</p>\n<p>Here, the <em>record</em> refers to the current series.</p>\n<p>You can read more about relationships here —\n<a href=\"https://docs.bolt.cm/3.4/contenttypes/relationships#\">https://docs.bolt.cm/3.4/contenttypes/relationships#</a></p>\n<p>About relations in templates —\n<a href=\"https://docs.bolt.cm/3.4/contenttypes/relationships#relations-in-templates\">https://docs.bolt.cm/3.4/contenttypes/relationships#relations-in-templates</a></p>\n<p>This is the first project that I have developed with Bolt CMS and really liked\nworking with it so far, the extension ecosystem looks healthy and the future\nlooks promising.</p>","frontmatter":{"title":"Bolt CMS: Using content types and relations","date":"December 18, 2017","ogimage":null}}},"pageContext":{"slug":"/bolt-content-and-relations/","previous":{"fields":{"slug":"/react-redux-setup/"},"frontmatter":{"title":"Dev Diary: My React, Redux & React Router Setup."}},"next":{"fields":{"slug":"/angular-structural-vs-attribute-directives/"},"frontmatter":{"title":"Strucural vs Attribute Directives in Angular"}}}},"staticQueryHashes":["426816048","983108779"]}