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

slice theme helper #21742

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

muratcorlu
Copy link

slice helper is a very useful helper for theme developers to do stuff while generating their HTML.

most common requirement is having hierarchical navigations. Currenytly many theme developers fixes this with client-side JS which is not a convenient solution.

Example, partial navigation menu:

Using a part of navigation in a specific place. If a secondary navigation item label starts with @ , then list them in a specific place.

<h2>Find me on other places:</h2>
<ul>
  {{#foreach @site.secondary_navigation}}
    {{#match (slice label start=0 end=2) "@ " }}
      <li><a href="{{url}}">{{ slice label start=2 }}</a></li>
    {{/match}}
  {{#foreach}}
</ul>

Example, hierarchical menu

This notation suggests to have a hierarchical menu by navigation labels like below:

Home
Services [
Software Development
Marketing
Design
] Contact
<ul>
  {{#foreach @site.navigation}}
    {{#match (slice label start=-1) "[" }}
        <li><a href="{{url}}">{{ slice label start=0 end=-2 }}</a></li>
        <ul>
    {{else}}
        {{#match (slice label start=0 end=1) "]" }}
            </ul>
            <li><a href="{{url}}">{{ slice label start=2 }}</a></li>
        {{else}}
             <li><a href="{{url}}">{{ label }}</a></li>
        {{/match}
    {{/match}}
  {{#foreach}}
</ul>

There can be also other smart use cases with a naming convention used with internal tags.

I hope you consider my proposal.

Thanks in advance!

muratcorlu and others added 2 commits November 27, 2024 14:07
no issue

slice helper is a very useful helper for theme developers to do stuff while generating their HTML.

most common requirement is having hierarchical navigations. Currenytly many theme developers fixes
this with client-side JS which is not a convenient solution.

There can be also oter smart use cases with a naming convention used with internal tags.
@cathysarisky
Copy link
Contributor

I think you'll also need to add it to the list of helpers. See this recent PR for an example:
https://github.com/TryGhost/Ghost/pull/21151/files

@muratcorlu
Copy link
Author

Thank you @cathysarisky . I updated helper test file as well.

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

Successfully merging this pull request may close these issues.

2 participants