When I print my project, that includes different layers, I always end up with all the layers in the legend. What I want when printing is to only show 1 layer, that always has the same name "Werken". The rest of the layers are not necessary to be shown in the legend. What kind of expression would I have to write to become this result?
Legend filter expressions only apply on a per-layer basis. In other words, you can apply a filter to one layer at a time. You can't apply a filter to all layers in the legend.
So there's no way to use an expression to control which layers are displayed in the legend.
It's quite easy to remove layers you don't want manually. There are two ways:
- Select the layers you don't want in the legend, and click the red minus button.
- If you have a lot of layers, and have trouble finding the one layer that you want to keep, simply remove all the layers as in step 1. Then click the green plus button, and add the layer you do want.
Once the legend is set up how you want it, you can re-use the same legend in other print layouts.
- When you create a new print layout in the same project, you can copy and paste the legend from the old print layout into the new layout.
- Save the print layout as a template. When you open a different project, load the saved template into a blank print layout.
Note: This answer applies to the GUI (graphical user interface) only. It might be possible to solve this problem using pyqgis in the Python Console, but that's outside the scope of the question as it's written. If you want a pyqgis solution, be aware that questions on this site asking for code without including a code snippet will be closed for this reason:
Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example.