Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing pages in menu list automatically as they are created #178

Open
sensaetions opened this issue Jan 31, 2019 · 10 comments
Open

Listing pages in menu list automatically as they are created #178

sensaetions opened this issue Jan 31, 2019 · 10 comments

Comments

@sensaetions
Copy link

sensaetions commented Jan 31, 2019

Hello,
I have a desire to automatically list pages to a menu list. How can I go about doing this (creating the menu list of pages automatically) with panini when the pages are created in the /src/pages folder?

Thank you in advance!

@sensaetions sensaetions changed the title Listing pages automatically Listing pages in menu list automatically as they are created Jan 31, 2019
@angelicochris
Copy link

I am also in need of this functionality.

@DanielRuf
Copy link
Contributor

You might want to create a custom handlebars helper for this as panini is based on handlebars.

@angelicochris
Copy link

angelicochris commented Aug 13, 2020

Is there a way to add these helpers to the foundation stack to use them?
https://github.com/helpers/handlebars-helpers
Panini's custom helpers seem to require each helper have it's own .js file while these helpers have multiples in different .js files.

@DanielRuf
Copy link
Contributor

Yes, you can define it in the configuration.

https://github.com/foundation/panini/blob/develop/index.js#L27

https://github.com/foundation/panini/blob/develop/lib/loadHelpers.js#L6-L10

image

https://github.com/foundation/panini#usage

Panini's custom helpers seem to require each helper have it's own .js file while these helpers have multiples in different .js files.

I'm not 100% sure but this should not be a problem. But self-contained helpers are often probably better. Best it you try what works as I have not used Panini for a long time.

@angelicochris
Copy link

Ok, this is going to be a really noob question, but if I have the handlerbars-helpers package installed how do I point my config to those helpers? I shouldn't have to/can't point it to the node_modules folder its in right?
If they do require being individuals js thats going to make this a huge pain because now I need to port all the helpers I need -_-

@DanielRuf
Copy link
Contributor

Ok, this is going to be a really noob question, but if I have the handlerbars-helpers package installed how do I point my config to those helpers? I shouldn't have to/can't point it to the node_modules folder its in right?

Technically you can do it but it's better to copy the needed helpers into your project and reference this path like we do it in the readme.

@angelicochris
Copy link

image
According to this the helper ends up being the name of the js file. Maybe I can do it by proxy?
Include the handlebars-helper in the helpers/myhelper.js file and then call the helper function I want from there?
image
https://github.com/helpers/handlebars-helpers/tree/master/lib
Problem is like I said their helpers js files have multiple helpers in them. would I be able to do something like array.withSort if I got it to include the array.js from their helper libs?

@DanielRuf
Copy link
Contributor

According to this the helper ends up being the name of the js file. Maybe I can do it by proxy?
Include the handlebars-helper in the helpers/myhelper.js file and then call the helper function I want from there?

That shouldwork, yes, the required / imported packages / modules inside of them should be resolved by Nodejs itself so you can do anything you want in there, even require / import things from node_modules by package name or path).

@DanielRuf
Copy link
Contributor

Problem is like I said their helpers js files have multiple helpers in them. would I be able to do something like array.withSort if I got it to include the array.js from their helper libs?

Probably not possible, but I never tried to achieve something like this. Maybe there is some way.

@angelicochris
Copy link

angelicochris commented Aug 13, 2020

I got this to work inside my own helper.js

var fs = require("handlebars-helpers/lib/fs")

module.exports = function (dir, filters) {
    var items = fs.readdir(dir, filters);
    for (var i = 0; i < items.length; i++) {
        items[i] = items[i].replace('src\\pages\\', '');
    }
    return items;
}

A bit modified from the main helper, but it works. So it is possible to, just kind of a pain.
Now my only problem is I can't iterate through the list I get

<div>
    <h1>Kutztown University</h1>
    <h2>Templates</h2>
    <ul class="zebra-striping">
        {{#readdir 'src/pages'}}
        {{#each this}}
        <li><a href="{{ this }}.html">{{ this }}</a></li>
        {{/each}}
        {{/readdir}}
    </ul>
</div>

I don't know how to actually go through it. If I just put {{ this }} in between the readdir it outputs it, but removing the each doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants