How do you loop through static pages [If they exist] - ghost-blog

I made a navigational bar at the left side of my blog and I wanted to add the list of pages that the user created into that navigational element. The problem is that I do not know how to loop through static pages. When looping through normal posts all users approach this method:
{{#foreach posts}}
....
....
....
{{/foreach}}
The above code is to loop through each post that exists and then the user has the choice to put whatever they want inside that piece of code. The problem is now looping through each static page.
Can anyone show me how to loop through static pages?

At this time, it is currently not possible to loop through static pages :(
That will prob come out when Apps do (aka someone will make an app for it)

I was searching for just this today and found a solution on this Github issue
{{#get "posts" filter="featured:true+page:true"}}
{{#foreach posts}}
... do something with all featured pages...
{{/foreach}}
{{/get}}
I just verified this locally.

Related

How to get internal tag posts in Ghost

I'm currently working on a Ghost blog, but I'm wondering how I might be able to grab all the posts that have a internal tag in Ghost.
I found
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{removeSubstring name '#META:'}}
{{/foreach}}
{{/get}}
this code but it only returns tag list not posts.
I want a internal tag posts list, Can anyone please help me ?
When you say internal tags do you mean Private Tags? If so then that's not really what private tags are for, you can filter with them though like so:
{{#get "posts" filter="tag:hash-tagname"}}
{{#foreach posts}}
{{title}}
{{/foreach}}
{{/get}}
To get all public tags use the following:
{{#get "tags" limit="all"}}
{{tags}}
{{/get}}
Hope this helps!

Ghost - how to get a specific page?

I'm a Ghost beginner, and I know I can get the list of pages doing like below.
{{#get "pages"}}
{{#foreach pages}}
{{{html}}}
{{/foreach}}
{{/get}}
But am I able to fetch a specific page? Let's assume that I have an "about" page that I'd like to fetch in order to show its contents into the blog's sidebar, for example, this is what I tried, but it's not working.
{{#get "pages/slug/about" as page}}
{{page}} // prints undefined
{{/get}}
Any help would be much appreciated.
The first parameter passed to the #get helper specifies the name of the resource you want to query. It should be either posts, tags or authors. In your use case it should be posts.
{{#get "posts" slug="pages/slug/about" as |post|}}
{{#post}}
<h1>{{title}}</h1>
<div class="post-content"> {{content}} </div>
{{/post}}
{{/get}}

How to get all pages from Ghost blog platform, using the get helper

I am trying to get all pages from ghost blog.
{{#get "posts" limit="all" filter="page:true"}}
Doesn't work.
If you are running on latest Ghost instance (or at least the version that has Content API ^2.10.0).
You can use limit=all attribute to fetch all page resouces like so:
{{#get "pages" limit="all"}}...{{/get}}
You can find more about the limit attribute in Ghost Docs for {{get}} helper and page resource here

Internal Tag Parsing in Ghost

Within ghost if I use the following to display all internal tags,
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{name}}
{{/foreach}}
{{/get}}
How do I display a tag that has a certain string and then string off the beginning.
i.e I want to add an internal tag of:
#META:Cisco / ASA / 8.2.1
But to print Cisco / ASA / 8.2.1 only
Nice question. :)
Unfortunately, I don't think you can do this simply using the built-in features, but you
can create a custom app that registers a custom helper that can do this.
Here's how to do that:
Install the ghost-app package to your Ghost installation
Check out the docs on how to create an app.
Create the app. :)
Modify gscan to recognize your helper.
Since I found your question interesting, I implemented this app myself. You can view and download the source code from here: https://github.com/conwid/RemovesubstringApp
I also wrote a little blog post about how I created it and how you can set it up and modify gscan in detail here: https://dotnetfalcon.com/stackoverflow-adventures-creating-custom-ghost-helpers-using-apps/
With my version, you'll be able to write this in your templates:
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{removeSubstring name '#META:'}}
{{/foreach}}
{{/get}}
Hope this helps, if you have problems with the implementation or the setup, feel free to ask.

How do I place a configurable meme at the bottom of the index page in ghost?

I'm working on a blog for a friend of mine who wants to put a meme picture at the bottom of the index page.
So the simplest way is to edit the template and reference it from there.
The problem is, it's not user friendly to keep editing and uploading a new template.
So I had this idea that I could create a static page and place it on that page and reference it from the template. But I see that when you upload an image to ghost.io it generates a name based on the date path. That's not going to work for a fixed URL in the template.
Another option might be to use the tags. As tags allows you to put a picture and has a URL. But I tried that it also has similar problems.
How can I make this work nicely?
Don't reference image URL in your theme. Reference page slug and load its content, which would be just an image.
Example with Ghost Handlebars API:
{{!-- If a static page "meme" exists - its content will be loaded here --}}
{{#get "posts" slug="meme" }}
{{#foreach posts}}
<div>
{{content}}
</div>
{{/foreach}}
{{/get}}

Resources