Skip to content

Commit 95cddb4

Browse files
feat(directives): Add @hasoptions & @endhasoptions (#54)
1 parent 6cf5181 commit 95cddb4

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/usage/acf.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ If the option you are checking against is an array, you can pass the array key a
389389
`@options` acts as a helper for handling repeater and group fields within' your theme options. Under the hood, it is essentially the exact same as `@fields` and `@group` except it automatically has the theme options ID `'option'` passed to it. It can be closed using `@endoptions`.
390390

391391
```php
392-
@hasoption('social')
392+
@hasoptions('social')
393393
<ul class="social">
394394
@options('social')
395395
<li>
@@ -404,5 +404,19 @@ If the option you are checking against is an array, you can pass the array key a
404404
</li>
405405
@endoptions
406406
</ul>
407-
@endoption
407+
@endhasoptions
408+
```
409+
410+
## @hasoptions
411+
412+
`@hasoptions` is a simple conditional checking if a parent field from your theme options (such as Repeater or Flexible Content) has any rows of data to loop over. It can be closed using `@endhasoptions`
413+
414+
```php
415+
@hasoptions('socials')
416+
<ul>
417+
@options('socials')
418+
<li>@sub('social')</li>
419+
@endoptions
420+
</ul>
421+
@endhasoptions
408422
```

src/Directives/ACF.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227

228228
/*
229229
|---------------------------------------------------------------------
230-
| @options / @endoptions
230+
| @options / @endoptions / @hasoptions / @endhasoptions
231231
|---------------------------------------------------------------------
232232
*/
233233

@@ -239,6 +239,14 @@
239239
'endoptions' => function () {
240240
return "<?php endwhile; endif; ?>";
241241
},
242+
243+
'hasoptions' => function ($expression) {
244+
return "<?php if (have_rows({$expression}, 'option')) : ?>";
245+
},
246+
247+
'endhasoptions' => function () {
248+
return "<?php endif; ?>";
249+
},
242250

243251
/*
244252
|---------------------------------------------------------------------

0 commit comments

Comments
 (0)