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

@hasfield compiled incorrectly #44

Closed
DaveFlynn opened this issue Sep 2, 2020 · 1 comment · Fixed by #82
Closed

@hasfield compiled incorrectly #44

DaveFlynn opened this issue Sep 2, 2020 · 1 comment · Fixed by #82

Comments

@DaveFlynn
Copy link

DaveFlynn commented Sep 2, 2020

Got a weird issue in Sage 10 with @hasfield not compiling correctly:

This:

@hasfield('menu_section', $menu_id )
    <ul>
        @fields('menu_section', $menu_id)
            <li>
                @sub('section_title')
            </li>
        @endfields
    </ul>
@endfield

Renders to this:

<?php if (get_field('menu_section')[$menu_id]) : ?>
    <ul>
        <?php if (have_rows('menu_section', $menu_id)) : ?><?php while (have_rows('menu_section', $menu_id)) : the_row(); ?>
            <li>
                <?= get_sub_field('section_title'); ?>
            </li>
        <?php endwhile; endif; ?>
    </ul>
<?php endif; ?>

For some reason @hasfield renders as get_field('menu_section')[$menu_id] instead of get_field('menu_section', $menu_id) and doesn't work. If I remove the @hasfield and @endfield the code works find and displays the list of section titles.

I've reverted to ACF code for now as a workaround:

<?php if (get_field('menu_section', $menu_id ) ) : ?>
    <ul>
        @fields('menu_section', $menu_id)
            <li>
                @sub('section_title')
            </li>
        @endfields
    </ul>
<?php endif; ?>
EHLOVader added a commit to EHLOVader/sage-directives that referenced this issue Nov 3, 2021
Switching to is_numeric to identify ID values from strings, since the blade template is always parsed as a string and is_string wasn't catching IDs.

Fixes Log1x#44
Fixes Log1x#63
EHLOVader added a commit to EHLOVader/sage-directives that referenced this issue Nov 3, 2021
Switching to is_numeric to identify ID values from strings, since the blade template is always parsed as a string and is_string wasn't catching IDs.

Fixes Log1x#44
Fixes Log1x#63
@EHLOVader
Copy link

@DaveFlynn do you know if #68 fixes your issue?

Can be tested with composer patches

@Log1x Log1x mentioned this issue Jul 29, 2023
@Log1x Log1x closed this as completed in #82 Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants