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

.HasAnyShortcode : return TRUE if a page uses at least one shortcode #7996

Open
jeremielp opened this issue Nov 27, 2020 · 6 comments
Open
Labels
Milestone

Comments

@jeremielp
Copy link

jeremielp commented Nov 27, 2020

Similar to .HasShortcode, but without having the need to specify a shortcode name as parameter.

.HasAnyShortcode would Return TRUE if at least one shortcode is used in the page else Return FALSE

Use case: CSS/JS libraries containing the code needed for a set of shortcodes. This would avoid to have to check for existence of all shortcodes one by one.

Alternatives could be:

  • a specific parameter for .HasShortcode, like .HasShortcode Any
  • use .HasShortcode with an array to test if one of the shortcodes in the array is used
@bep
Copy link
Member

bep commented Nov 27, 2020

I agree about the "we need this", but I'm not sure we need another method. I think it fits with what we do in other areas of the template funcs that we have a vararg argument. So if we make HasShortCode(... string) I think most people would understand if we document it.

/cc @moorereason

@bep bep closed this as completed Nov 27, 2020
@bep bep reopened this Nov 27, 2020
@bep bep added this to the v0.80 milestone Nov 27, 2020
moorereason added a commit to moorereason/hugo that referenced this issue Nov 28, 2020
Make HasShortcode parameter variadic to allow for the testing of any
shortcodes instead of only named shortcodes.

Fixes gohugoio#7996
@bep
Copy link
Member

bep commented Nov 28, 2020

OK, looking at the use case, I think I misunderstood the use case, but know I think. I do, and I take back what I said about "retrofitting" the HasShortcode.

I think we need a method HasShortCodeAny which returns true if one of the given shortcode names is in use.

@moorereason
Copy link
Contributor

First, as is usually the case, when I program late at night, I usually missing something. In this case, I didn't catch the fact that this PR is proposing two changes:

  1. Allow to test for any unnamed shortcodes.
  2. Allow to test for any of a list of named shortcodes.

My PR retrofitting HasShortcode only attempted to address the first request.

@bep,
As for your new proposal, are you suggesting we leave HasShortcode unchanged and put these new features into HasShortcodeAny alone?

@bep
Copy link
Member

bep commented Nov 28, 2020

Let us create HasShortcodeAny; which returns true if any of the shortcode names given is in use.

@moorereason
Copy link
Contributor

What about the existing PR and the test for any unnamed shortcodes case?

@jeremielp
Copy link
Author

jeremielp commented Nov 29, 2020

FYI, what I finally did, as I had the case for both partials and shortcodes, is setting a boolean to true in the partial/shortcode using .Scratch.Set, and checking for that boolean to include or not my javascripts. These are all in the footer, after the shortcodes. I have not tested if this work for CSS in the <head> though.

@bep bep modified the milestones: v0.80, v0.81 Jan 2, 2021
@bep bep modified the milestones: v0.81, v0.82 Feb 19, 2021
@bep bep modified the milestones: v0.82, v0.83 Mar 21, 2021
@bep bep modified the milestones: v0.83, v0.84 May 1, 2021
@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants