# Adding Browser Fields to a Block
To attach other records inside of a block, it is possible to use the browser field.
- In a block, use the
browserfield:
filename: views/admin/blocks/products.blade.php
@twillBlockTitle('Products')
@formField('browser', [
'routePrefix' => 'shop',
'moduleName' => 'products',
'name' => 'products',
'label' => 'Products',
'max' => 10
])
- If the module you are browsing is not at the root of your admin, you should use the
browser_route_prefixesarray in the configuration in addition toroutePrefixin the form field declaration:
'block_editor' => [
...
'browser_route_prefixes' => [
'products' => 'shop',
],
...
],
- When rendering the blocks on the frontend you can get the browser items selected in the block, by using the
browserIdshelper to retrieve the selected items' ids, and then you may use Eloquent method likefindto get the actual records. Example in a blade template:
filename: views/site/blocks/blockWithBrowser.blade.php
@php
$selected_items_ids = $block->browserIds('browserFieldName');
$items = Item::find($selected_items_ids);
@endphp
- When the browser field allows multiple modules/endpoints, you can also use the
getRelatedfunction on the block:
filename: views/site/blocks/blockWithBrowser.blade.php
@php
$selected_items = $block->getRelated('browserFieldName');
@endphp