How to disable post or page for some languages?
Created 7 years ago by pwrobelHi! I've got a small question. I work with multilingual page, but I need to disable some post and pages in some languages. I know that I can leave fields empty, that works, but when I edit post or page, empty fields in other languages are filled with default language content. How can I fix it?
@pwrobel I would go about it with a middleware defined in config/streams.php
and a flag / field on the posts that you can read. If you handle the response first then you can inject / look in the ViewTemplate
super variable that get's passed to views and grab the post / do your testing that way. If all is well return the response.
Basically the equivalent of what Laravel used to call "after filters".
This way you can keep your logic out of the view and control the response better overall.
There might be an easier option than this, but one approach would be to assign a field to your post/page that gets the user to select if the post/page is enabled in a specific locale (e.g. it could be checkboxes for the user to select any locales they don't want their page to be available for). Then do a check in the post/page view to see if the current locale - which you can get with
{{ config_get('app.locale') }}
- is in the allowed list. You'd obviously have to do a similar thing for post/page listings if you only want the ones allowed in a specific locale to be listed.E.g. if you had a boolean field
disable_for_fr
for a post, in your post view you could have:P.S. Overriding views can be done via a service provider, e.g.