Documentation Level: 
Intermediate
Documentation Status: 
No known problems

Rules that allow you to define the conditions when blocks or layouts are allowed to appear.

Visibility conditions are found in three different settings:

  • When creating a layout - allows this layout to selectively apply to different situations
  • When managing a menu path - conditions set at the menu level will prevent access to the entire page and all layouts configured in it.
  • When adding a block to a layout - allows this block to be shown only in certain situations

List of available visibility conditions

  • Front Page
  • Site language
  • URL Path
  • User permission
  • User: role
  • User: ID
  • Entity: ID
  • Entity: type

Layout visibility conditions

During creation or editing of a layout, visibility conditions can be added to determine access to the layout. If the user does not have access Backdrop will return a "Page not found" error.

Set multiple layouts on one path using visibility conditions

Multiple layouts can be made on the same path. This may seem unintuitive but is reasonable - because of visibility conditions. Although multiple layouts are on the same path, one may apply if condition A is true while the other when condition A is false. For example, two layouts may be active for your path 'company-details', but one may only show when the site user is anonymous, while the other only shows for other registered  users. This makes it possible to show entirely different sets of blocks and content based on the user role.

If there are multiple layouts at one path, the first one which is not invisible to the user is shown. Layouts can be re-ordered though, to guarantee the order of selection. If no layouts meet the visibility conditions, Backdrop will return a "Page not found" error.

For example, our menu path 'company-details' has three layouts defined:

  • the "Guest layout" is only visible to anonymous users
  • the "Editors layout" only to registered users of role 'editor' and 'executive'
  • the "Executive layout" only to registered users of role 'executive'

If an anonymous visitor attempts to visit http://my-site/company-details, he will only get the first layout, the Guest layout.

If an editor visits, he will only get the Editor layout

If an executive visits he will also get the Editor layout since this is the first layout which is visible. If however the layout order is switched so that the Executive layout is second, the executive will get the Executive layout since this is now the first visible layout.

Menu path visibility conditions

Conditions set on the menu path determine access to the whole path. If we have conditions set on this path a user who does not meet any of the visibility conditions will not have access to that path and will get an "Access denied" error from Backdrop, even if he meets the selection criteria for the individual layouts in this path.

So if for example a visibility condition was set on the 'company-details' menu path so  that only users with site language set to French were allowed access, any English-language visitors, editors or executives visiting this path would get an "Access denied" error. However, French users accessing this path would then have access based on the individual layout-based visibility conditions as described in the previous section.

If an anonymous visitor attempts to visit http://my-site/company-details, he will get an “Access denied” error, since anonymous users don’t have a language set.

If an editor visits, he will only get the Editor layout

If an executive visits he will also get the Editor layout unless we switched the layouts as described above..

Block visibility conditions

During creation or editing of a block, visibility conditions can be added to determine access to the block. If the user does not have access Backdrop will simply hide the block.

Adding a block visibility condition

  1. This example shows how to add conditions to a block, but the process is identical for adding menu level and layout conditions.
  2. Navigate to the layout list page at '/admin/structure/layouts' and click 'edit' on the default layout (or another layout as needed)
  3. Click 'Configure' on the block drop button; the blog edit dialog should open
  4. Scroll down to the 'Visibility conditions' fieldset, click it to expand, then click the "Add visibility condition" link; the Visibility Conditions form dialog should load
  5. In the select list, select a listed condition, for example, "Front page"; the options for this condition should load
  6. Select an option ("Current path is: The front page" for example)
  7. Click the "Add visibility condition" button
  8. Verify that your new condition is now listed
  9. Click "Save configuration" to go back to the layout edit page
  10. Click "Save layout" to save changes

Visit the front page of your site to verify that the block is shown; visit any other page to verify that it no longer shows.