1

I am using the searchtools filters in the front end of a custom component.

So I am displaying the fields in my template :

<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>

Everything works fine but in the mobile and tablet the searchtools shows only the search field and hides everything else. I do not want this. Is a custom component so I want to display all the filters even in mobile in a element that I control his visibility.

So I decided to render the fields the way I like in my tmpl/default.php file. The problem is that no field is rendering.

Here is the code : In the view :

$this->filterForm = $this->get('FilterForm');
JLog::add('filterform: ' . print_r($this->filterForm, TRUE), JLog::DEBUG, 'com_contract-site-ContractView');

And the log

DEBUG 127.0.0.1 com_contract-site-contractview  filterform: Joomla\CMS\Form\Form Object
(
    [data:protected] => Joomla\Registry\Registry Object
        (
            [data:protected] => stdClass Object
                (
                    [list] => stdClass Object
                        (
                            [limit] => 20
                        )
                )
            [initialized:protected] => 
            [separator] => .
        )    
    [xml:protected] => SimpleXMLElement Object
        (
            [fields] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [name] => filter
                                )    
                            [field] => Array
                                (
                                    [0] => SimpleXMLElement Object
                                        (
                                            [@attributes] => Array
                                                (
                                                    [name] => search
                                                    [type] => text
                                                    [label] => COM_CONTRACT_CONTRACTS_SEARCH_IN_TITLE
                                                    [hint] => JSEARCH_FILTER
                                                    [class] => js-stools-search-string
                                                )

                                        )

                                    [1] => SimpleXMLElement Object
                                        (
                                            [@attributes] => Array
                                                (
                                                    [name] => published
                                                    [type] => status
                                                    [label] => JOPTION_SELECT_PUBLISHED
                                                    [description] => JOPTION_SELECT_PUBLISHED_DESC
                                                    [onchange] => this.form.submit();
                                                )

                                            [option] => JOPTION_SELECT_PUBLISHED
                                        )
                                    )
                        )
                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [name] => list
                                )

                            [field] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [name] => limit
                                            [type] => limitbox
                                            [class] => input-mini
                                            [default] => 25
                                            [label] => COM_CONTENT_LIST_LIMIT
                                            [description] => COM_CONTRACT_LIST_LIMIT_DESC
                                            [onchange] => this.form.submit();
                                        )

                                )

                        )

                )

        )

    [repeat] => 
)

So I got all the fields, but no field is rendered.

tmpl/default.php

<?php echo $this->filterForm->renderField('search'); ?>
<?php echo $this->filterForm->renderField('published'); ?>
<?php echo $this->filterForm->renderField('clientlist'); ?>

etc ...

Thank you

2

Include group name as the second parameter in renderField(), e.g.:

echo $this->filterForm->renderField('published', 'filter');
echo $this->filterForm->renderField('limit', 'list');

Or if you want to run a loop:

foreach ($this->filterForm->getGroup('filter') as $field)
{
    echo $field->renderField();
}

Also, you could create a custom version of /layouts/joomla/searchtools/default.php in your component's folder and remove the CSS classes there. If you maintain the folder structure, it will be able to load default sublayouts without having to copy them.

  • Thank you for your answer. The group is what was missing ! Now for the searchtools layout I wanted to avoid it because is a component. I will not be able to know which template is going to be used or another template will be installed in the future. – mixahlos Sep 27 '18 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.