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

Controller data not available in searchForm partial #2105

Closed
2 of 6 tasks
NurdinDev opened this issue Aug 31, 2018 · 2 comments
Closed
2 of 6 tasks

Controller data not available in searchForm partial #2105

NurdinDev opened this issue Aug 31, 2018 · 2 comments
Labels

Comments

@NurdinDev
Copy link

NurdinDev commented Aug 31, 2018

Submit a feature request or bug report

Bug report

the staps ..
install new Sage theme ---> remove all posts from admin ---> and see the error in the home page.

this section will execute:

 @if (!have_posts())
    <div class="alert alert-warning">
      {{ __('Sorry, no results were found.', 'sage') }}
    </div>
    {!! get_search_form() !!}
  @endif

the error is Undefined variables...

The error in my opinion is:
because the variables not passed to the "formSearch" partial page as well.

the data injected here

add_filter('sage/template/app/data', function ($data) {
    return $data + [
        'sf_action' => esc_url(home_url('/')),
        'sf_screen_reader_text' => _x('Search for:', 'label', 'sage'),
        'sf_placeholder' => esc_attr_x('Search &hellip;', 'placeholder', 'sage'),
        'sf_current_query' => get_search_query(),
        'sf_submit_text' => esc_attr_x('Search', 'submit button', 'sage'),
    ];
});

but "formSearch" use this data but he can't access the data above.

Please describe your local environment:

WordPress version: latest

OS: macOsx

NPM/Node version: 6.4.0/ 10.0.0

Where did the bug happen? Development or remote servers?

Development

@mmirus mmirus changed the title data not passed to the partial pages "Bug in Sage first installation" Controller data not available in searchForm partial Aug 31, 2018
@mmirus
Copy link
Contributor

mmirus commented Aug 31, 2018

Also reported in #2101 and referenced on Discourse here.

As reported, the controller data for the searchForm partial defined at https://github.com/roots/sage/blob/master/app/filters.php#L95 is available within templates but not within that partial.

One possible solution would be this:

/**
 * Render WordPress searchform using Blade
 */
add_filter('get_search_form', function () {
    $data = collect(get_body_class())->reduce(function ($data, $class) {
        return apply_filters("sage/template/{$class}/data", $data, '/partials/searchform.blade.php');
    }, []);

    return template('partials.searchform', $data);
});

But we can probably come up with something cleaner.

@mmirus mmirus added the bug label Aug 31, 2018
@mmirus
Copy link
Contributor

mmirus commented Aug 31, 2018

#2100 deals with a similar issue with the comments partial. If that's merged and we used something like the above to resolve this issue, we'd be reproducing the data collection code in three spots. Perhaps it should be refactored to a new helper function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants