Open jeremielp opened 3 years ago
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
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.
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:
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?
Let us create HasShortcodeAny
; which returns true if any of the shortcode names given is in use.
What about the existing PR and the test for any unnamed shortcodes case?
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.
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 FALSEUse 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:
.HasShortcode
, like.HasShortcode Any
.HasShortcode
with an array to test if one of the shortcodes in the array is used