I'm a newbie trying to "get" the contents of a single "page" into a div on my local "index.hbs"

#1

I have a page with a slug of “about” and I’m trying to put the contents of that page into a div but the get helper doesn’t seem to do anything. I think I got it to return something just one time, out of all the things I’ve tried - it just returned the word ‘undefined’.

Meanwhile, I can use a foreach loop to return all of my posts without issue. Not sure how to use the same loop to return 1 specific page (not post) though.

I’m guessing that I’m either writing the code incorrectly or I’m just … not putting the code in the correct place or something. I tried it on my index.hbs and my post.hbs - those are the only 2 pages I have - with no success. I even pasted it right next to my foreach loop which works fine.

My ghost version is 2.18.1, and ghost CLI version is 1.9.9. I’m using the latest normal release version of chrome on a win10 machine.

Hoping that someone recognizes this issue and that it’s a simple straightforward path to a fix or troubleshooting. Oh, I’m new to coding in general (taking online courses as of the past few weeks) and even newer to ghost so … be gentle :-/

#2

@bigbird it would be really useful if you could post some examples of the code that you’re trying, without that it’s difficult to point you to what’s going wrong.

As for an example of {{get}} usage, this demonstrates fetching a single page with the slug about:

<div class="about-content">
    {{#get "pages" limit="1" filter="slug:about"}}
        {{#foreach pages}}
            {{content}}
        {{/foreach}}
    {{/get}}
</div>
#4

Sure I’ll share the code I’m using, my pages are pretty short. And thanks for the help.

This is my index.hbs and over here is my package.json file. If I insert that get code you posted in my about div, nothing happens. I can’t get the “get” function to do anything and I’m not sure what I’m missing.

The complete file structure of my theme is:

.
├── /assets
|   └── /css
|       ├── reset.css
|       ├── strap.css
|       ├── style2.css
|       ├── style.css
├── index.hbs 
└── post.hbs 
└── package.json
#5

So in an effort to test out whether or not my issue was the “get” command, I did some searching and found I could use the following code to get an individual posts contents to show up on my main page. This worked and returned the contents of the post with a “homepage” tag.

  {{#foreach posts}}
    {{#has tag="homepage"}}
      {{content}}
    {{/has}}
 {{/foreach}}

And then I tried to do the same thing using the “get” function with the following code and it did NOT work.

    {{#get "posts" filter="tag.name:'homepage'"}}
       {{#foreach posts}}
           {{content}}
       {{/foreach}}
   {{/get}}

So … yeah my issue is with the get function I think. How do I get this function to work?

closed #6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.