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

Request for loading custom layout #5146

Open
2 tasks done
WangNianyi2001 opened this issue Jan 15, 2023 · 1 comment
Open
2 tasks done

Request for loading custom layout #5146

WangNianyi2001 opened this issue Jan 15, 2023 · 1 comment

Comments

@WangNianyi2001
Copy link

WangNianyi2001 commented Jan 15, 2023

Check List

Please check followings before submitting a new feature request.

  • I have already read Docs page
  • I have already searched existing issues

Feature Request

Happy new year, 2023 here (kinda late tho).
This has been talked about back then in 2017 in #2645, but that didn't solve the essential problem.

I think that Hexo should support to load layout automatically from a custom /layout diretory without having to modify theme/*/layout/layout.ejs.
This fundamentally means that themes can be decoupled with the actual content of the site.

Let me show you what I mean:
Suppose (I'm doing this irl really) that I'm building a website not only containing blog articles, but all other kinds of content, say ideas or song lists, and I want to organize them under different pages, and to have a nav bar linking to all these pages.
This could be done by applying categories on posts though, but in my case I want to have different sub-index page for each category. Auto generated category pages won't work, so essentially they have to use different layouts.

Since the nav bar is written in a theme, and the actual content types would be indefinite, I left a configuring option in _config.yml to let the theme EJS know what should be presented in the nav bar (see the actual codes).

After this, I should be able to move all the sub-index layout files out from the theme directory, to /layout under the root directory. But when I actually do this, I noticed that all them pages with a custom layout had gone empty.

This means that custom layouts outside a theme can't be loaded, which further means that such content system can not be decoupled with its theme. Tracing back the old issue I realized this is certainly a design problem of Hexo.

Others

When I first tried to implement such thing, I tried simply setting all individual entries' layouts (for example if I want a new blog article I'd create a new but with layout: blog), and then I can iterate through them in blogs.ejs via <% for(const blog of site.blogs._data) %>.
Then I (very sadly) found out that no pages other than those with layout set to post/page can be access in the site variable.

This should be fixed, probably by adding a .layouts member to site.

P.S. If you actually visit my blog site you'll see that I've got it equipped with multilingual support. I personally think that my solution is more elegant than using i18n. I hope to hear some advice of this from you!

@nexmoe
Copy link

nexmoe commented Feb 8, 2023

I have the same need

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

2 participants