Using headless pages in section lists in hugo











up vote
0
down vote

favorite












I've got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.



I thought that a good way to do this might be to use headless pages.



It looks like to do that, these fragments must have a directory with an index.md, and should be accessible using the .Site.GetPage operator.



I'm struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2..n user sections, and I don't want to rebuild the section's template if the number of content modules changes.



I'm assuming either there's some magic to query multiple pages using .Site.GetPage, or there's an entirely different operator for this.



That, or I've completely misunderstood how to use headless pages.



Here's my template for the section (../layouts/the-range/section.html):



{{ define "main" }}
<div id="page-wrapper">
<div class="halfhero" id="map"></div>
</div>

{{ $sections := .Site.GetPage "/the-range/*" }}
<!-- leaf content at .../content/the-range/*/*.md -->
{{ range $sections }}
<section class="range-section">
<div class="section-content">
{{.Content}}
</div>
<img src="{{.Site.BaseURL}}{{.Params.images}}">
</section>

{{ end }}
{{ end }}


The headless content is just a series of markdown files as leaf bundles.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I've got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.



    I thought that a good way to do this might be to use headless pages.



    It looks like to do that, these fragments must have a directory with an index.md, and should be accessible using the .Site.GetPage operator.



    I'm struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2..n user sections, and I don't want to rebuild the section's template if the number of content modules changes.



    I'm assuming either there's some magic to query multiple pages using .Site.GetPage, or there's an entirely different operator for this.



    That, or I've completely misunderstood how to use headless pages.



    Here's my template for the section (../layouts/the-range/section.html):



    {{ define "main" }}
    <div id="page-wrapper">
    <div class="halfhero" id="map"></div>
    </div>

    {{ $sections := .Site.GetPage "/the-range/*" }}
    <!-- leaf content at .../content/the-range/*/*.md -->
    {{ range $sections }}
    <section class="range-section">
    <div class="section-content">
    {{.Content}}
    </div>
    <img src="{{.Site.BaseURL}}{{.Params.images}}">
    </section>

    {{ end }}
    {{ end }}


    The headless content is just a series of markdown files as leaf bundles.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I've got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.



      I thought that a good way to do this might be to use headless pages.



      It looks like to do that, these fragments must have a directory with an index.md, and should be accessible using the .Site.GetPage operator.



      I'm struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2..n user sections, and I don't want to rebuild the section's template if the number of content modules changes.



      I'm assuming either there's some magic to query multiple pages using .Site.GetPage, or there's an entirely different operator for this.



      That, or I've completely misunderstood how to use headless pages.



      Here's my template for the section (../layouts/the-range/section.html):



      {{ define "main" }}
      <div id="page-wrapper">
      <div class="halfhero" id="map"></div>
      </div>

      {{ $sections := .Site.GetPage "/the-range/*" }}
      <!-- leaf content at .../content/the-range/*/*.md -->
      {{ range $sections }}
      <section class="range-section">
      <div class="section-content">
      {{.Content}}
      </div>
      <img src="{{.Site.BaseURL}}{{.Params.images}}">
      </section>

      {{ end }}
      {{ end }}


      The headless content is just a series of markdown files as leaf bundles.










      share|improve this question













      I've got a requirement to build a section page that is comprised of some static header material, static footer material, and several sections of user-managed content. This user managed content is fragmentary, and as such should not have a permalink.



      I thought that a good way to do this might be to use headless pages.



      It looks like to do that, these fragments must have a directory with an index.md, and should be accessible using the .Site.GetPage operator.



      I'm struggling with figuring out how to use .Site.GetPage to get a list of pages to iterate over. There will be 2..n user sections, and I don't want to rebuild the section's template if the number of content modules changes.



      I'm assuming either there's some magic to query multiple pages using .Site.GetPage, or there's an entirely different operator for this.



      That, or I've completely misunderstood how to use headless pages.



      Here's my template for the section (../layouts/the-range/section.html):



      {{ define "main" }}
      <div id="page-wrapper">
      <div class="halfhero" id="map"></div>
      </div>

      {{ $sections := .Site.GetPage "/the-range/*" }}
      <!-- leaf content at .../content/the-range/*/*.md -->
      {{ range $sections }}
      <section class="range-section">
      <div class="section-content">
      {{.Content}}
      </div>
      <img src="{{.Site.BaseURL}}{{.Params.images}}">
      </section>

      {{ end }}
      {{ end }}


      The headless content is just a series of markdown files as leaf bundles.







      hugo






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 21:00









      PaulProgrammer

      8,14212042




      8,14212042
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2



          Given a structure like this:



          content/headless/
          ├── index.md # headless = true in front matter
          ├── five.md
          ├── four
          │ └── index.md
          ├── one
          │ └── index.md
          ├── three
          │ └── index.md
          └── two
          └── index.md


          You can do:



          {{ $headlessbundle := .Site.GetPage "/headless" }}
          {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
          {{.}}
          {{ end }}


          Which should output:



          Page(/headless/five.md) 
          Page(/headless/four/index.md)
          Page(/headless/three/index.md)
          Page(/headless/two/index.md)
          Page(/headless/one/index.md)





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270027%2fusing-headless-pages-in-section-lists-in-hugo%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2



            Given a structure like this:



            content/headless/
            ├── index.md # headless = true in front matter
            ├── five.md
            ├── four
            │ └── index.md
            ├── one
            │ └── index.md
            ├── three
            │ └── index.md
            └── two
            └── index.md


            You can do:



            {{ $headlessbundle := .Site.GetPage "/headless" }}
            {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
            {{.}}
            {{ end }}


            Which should output:



            Page(/headless/five.md) 
            Page(/headless/four/index.md)
            Page(/headless/three/index.md)
            Page(/headless/two/index.md)
            Page(/headless/one/index.md)





            share|improve this answer

























              up vote
              0
              down vote













              Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2



              Given a structure like this:



              content/headless/
              ├── index.md # headless = true in front matter
              ├── five.md
              ├── four
              │ └── index.md
              ├── one
              │ └── index.md
              ├── three
              │ └── index.md
              └── two
              └── index.md


              You can do:



              {{ $headlessbundle := .Site.GetPage "/headless" }}
              {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
              {{.}}
              {{ end }}


              Which should output:



              Page(/headless/five.md) 
              Page(/headless/four/index.md)
              Page(/headless/three/index.md)
              Page(/headless/two/index.md)
              Page(/headless/one/index.md)





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2



                Given a structure like this:



                content/headless/
                ├── index.md # headless = true in front matter
                ├── five.md
                ├── four
                │ └── index.md
                ├── one
                │ └── index.md
                ├── three
                │ └── index.md
                └── two
                └── index.md


                You can do:



                {{ $headlessbundle := .Site.GetPage "/headless" }}
                {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
                {{.}}
                {{ end }}


                Which should output:



                Page(/headless/five.md) 
                Page(/headless/four/index.md)
                Page(/headless/three/index.md)
                Page(/headless/two/index.md)
                Page(/headless/one/index.md)





                share|improve this answer












                Via the Hugo community at https://discourse.gohugo.io/t/using-headless-pages-in-section-lists-in-hugo/15275/2



                Given a structure like this:



                content/headless/
                ├── index.md # headless = true in front matter
                ├── five.md
                ├── four
                │ └── index.md
                ├── one
                │ └── index.md
                ├── three
                │ └── index.md
                └── two
                └── index.md


                You can do:



                {{ $headlessbundle := .Site.GetPage "/headless" }}
                {{ range ( $headlessbundle.Resources.ByType "page" ) }} <br>
                {{.}}
                {{ end }}


                Which should output:



                Page(/headless/five.md) 
                Page(/headless/four/index.md)
                Page(/headless/three/index.md)
                Page(/headless/two/index.md)
                Page(/headless/one/index.md)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 at 16:01









                PaulProgrammer

                8,14212042




                8,14212042






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270027%2fusing-headless-pages-in-section-lists-in-hugo%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents