Plone 5 search CheckBox checked by default "Only in current section"

Hello,

Can you help me please, I want modify the template zope.interface.interface-plone.searchbox , because I want that the check box "Only in current section" are checked by default.

Someone have an idea ?

    <div class="searchSection">
        <input id="searchbox_currentfolder_only"
               class="noborder"
               type="checkbox"
               name="path"
               tal:attributes="value view/folder_path;
                               checked request/form/path|nothing"
               />
        <label for="searchbox_currentfolder_only"
               i18n:translate="label_searchbox_currentfolder_only"
               style="cursor: pointer">
            only in current section
        </label>
    </div>

Thanks in advance for your reply.

Ahmed.

Just for your information :

It's what I want to do.

You can do it through the web, just go to ZMI > portal_view_customizations and look for the template.

Alternatively you can do an override in your site's package, using z3c.jbot or ZCML directly.

Thanks for you reply Davi :slight_smile:

I am on ZMI>portal_view_customizations > zope.interface.interface-plone.searchbox

But I don't know how I can change the code in order to check the checkbox by default:




only in current section

Ahmed

I add "checked" but it change nothing:

only in current section

Check the generated HTML after your change. You almost got it, only need to remove the line highlighted line above since it redefines what you did. Read more about Zope Templating: https://docs.zope.org/zope2/zope2book/AppendixC.html

1 Like

I wouldn't use portal_view_customisations as it makes it hard to upgrade later. Instead, in your diazo theme, define a rule which changes checked attribute. If you have no diazo theme enable, its easy to add a theme which lets all the html go through unchanged, except that change.

2 Likes

Just to be clear, @djay raises a good point in that if you customize any template you have to check if they changed and update accordingly when you upgrade your Plone version.

However beware that transferring customization work to the Diazo layer may bring comparable downsides. Basically instead of a bunch of templates to diff and update you may end up with a very extensive and hard to maintain rules.xml, which after a not so distant point drastically decays performance. Once I got into a project in which new developers were hating Plone because it was so slow. They were doing all customizations at Diazo layer, on a per section base, including multiple xi:includes and conditional HTMLs (since it was cumbersome to have multiple developers working in different sections of the same files). It was terrible, specially on development mode when all of these get recompiled at every request.

All in all I guess it depends on your usecase and taste. Mine is to keep rules.xml as simple (no xslt) and as short as possible (one more reason: Diazo debugging is hard). I try to make rules worry only about theming and prefer to control which information is shown at template level. But if the site won't grow much/you don't have too many rules in the horizon, Diazo may indeed serve you better.

1 Like

Sorry but I am a newbie with plone and I am not an expert with Python etc...

So after my change checked request/form/path|nothing"

I have this code which is generated :

> div class="searchSection"
> input id="searchbox_currentfolder_only" class="noborder" type="checkbox" name="path" value="/kb.preprod/en" /
> label for="searchbox_currentfolder_only" style="cursor: pointer">only in current section label
> /div

The "checked" doesn't appear, can you give me the correct syntax please...

i think is not a issue if i change only this section, I never develop in template it's just for this modification, I think I would upgrade without any problem.

@davilima6 Yes, its easy to create badly performing rules such as using xpath // too much. It would be nice if plone gave you warning when rules increase request time significantly. Also rules do break silently if the content html has changed in ways your rules don't expect. Again it would be nice if plone provided ways create tests for your diazo. Wither either template overrides or diazo you need to document what your customisation is intending to achieve to make it more maintainable.

Overall I think diazo wins in terms of learning curve. Determining which template to override is way harder, and template overrides often require learning both TAL and python. Diazo for us, has been easier to teach to non developers. Of course, you can do more with templates, so developers will tend to prefer it.

1 Like

You can't just modify only a small part of the template. You have to override of the whole template, and if you ever upgrade, or come across another plugin that also wants to override that template, then you have to be aware and mange this process yourself. You are effectively reaching in and messing with the innards of plone rather than using a more stable api.

I don't know how I can process... I'm not an expert with development or Plone ...

I thought that it's easy it just a checkbox ... Can you help me with my code...

Please can you help me it's urgent before I need to be operational for production quickly.

Ahmed

<div class="searchSection">
    <input id="searchbox_currentfolder_only"
           class="noborder"
           type="checkbox"
           name="path"
           checked
           tal:attributes="value view/folder_path"
           />
    <label for="searchbox_currentfolder_only"
           i18n:translate="label_searchbox_currentfolder_only"
           style="cursor: pointer">
        only in current section
    </label>
</div>

This should solve it. Notice all I did was remove one line from your original posting, as I'd already answered. If it doesn't work again please paste the full template after your modifications.

Thank you very much :slight_smile: it works

Remove 'checked' from tal:attributes and set the 'checked' attribute directly on the INPUT tag.

-aj