Fields
Link
Used for internal and external links
Installation
npx shadcn@latest add https://payload-bricks.bblank.dev/r/link-field.jsonUsage
import { linkField } from "@/fields/link"
import type { Block } from "payload"
export const ExampleBlock: Block = {
slug: "example",
interfaceName: "Example",
fields: [
// your other fields
linkField,
],
}import { getHrefByLink } from "@/lib/get-href-by-link"
import type { Example } from "@/payload-types"
import Link from "next/link"
export function ExampleBlock(props: Example) {
const href = getHrefByLink(props.link)
if (!href) return null
return (
<Link
href={href}
target={props.link?.newTab ? "_blank" : undefined}
rel={props.link?.newTab ? "noopener noreferrer" : undefined}
>
{props.link?.label}
</Link>
)
}Field structure
| name | type | |
|---|---|---|
type | radio | reference, custom |
newTab | checkbox | |
reference | relationship | shown for internal links |
url | text | shown for custom URLs |
label | text |
Customization
Internal links can point to the collections referenced in lib/collections.ts. Change collectionsWithPage to match the collections that have frontend pages in your project. The collections should use the Nested Docs Plugin. If you don't want to use that plugin, you need to update getHrefByLink.