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

✨ Added "startsWith" check to the match helper #18411

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ramrami
Copy link

@ramrami ramrami commented Oct 2, 2023

Added "startsWith" string comparison to the match helper.

I think this simple check will unlock and simplify a lot of use cases for theme developers:

Group logic when dealing with similar custom settings:

{{!-- Suppose layout could be: "List full", "List narrow", "Grid 2 cols", "Grid 3 cols", "Grid masonry" --}}
{{#match @custom.layout "startsWith" "Grid"}} 
    has-grid
{{/match}}

Check if a URL is external:

{{^match (url absolute="true") "startsWith" @site.url }} 
    is-external
{{/match}}

Simulate nested tags:

{{#match slug "startsWith" "hash-parent-tag-" }} 
    {{> template-parent }}
{{/match}}

Help implementing nested navigation:

{{#match label "startsWith" "--" }} 
    is-child-nav-item
{{/match}}

Add a badge to a navigation item:

{{#match label "startsWith" "[NEW]" }} 
    <span>{{t "NEW"}}</span>
{{/match}}

Please include a description of your change & check your PR against this list, thanks!

  • There's a clear use-case for this code change, explained below
  • Commit message has a short title & references relevant issues
  • The build will pass (run yarn test:all and yarn lint)

We appreciate your contribution!


🤖 Generated by Copilot at 082c4f9

This pull request adds support for the startsWith operator to the match template helper, which allows matching data values against string prefixes. It also adds unit tests for the new operator in the match.test.js file.

@ramrami
Copy link
Author

ramrami commented Oct 17, 2023

@ErisDS Any chance we can get this to upstream?

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.

1 participant