Link

Link to the web, link to internal content, or link to a media library file.

Link to anything (external URL, internal content or media library file):

Copy
      "link" : {
  "type" : "Link",
  "fieldset" : "Link to anything",
  "config" : {
    "placeholder" : "Link to anything"
  }
}
    

Link to the web:

Copy
      "weblink" : {
  "type" : "Link",
  "fieldset" : "Link to the web",
  "config" : {
    "select" : "web",
    "placeholder" : "Link to the web"
  }
}
    

Link to an internal content with a filter set to a specific custom type:

Copy
      "documentlink" : {
  "type" : "Link",
  "fieldset" : "Link to a document",
  "config" : {
    "select" : "document",
    "customtypes" : [ "type" ],
    "tags" : [ "tag" ],
    "placeholder" : "Link to a document"
  }
}
    

Link to a media library file:

Copy
      "medialink" : {
  "type" : "Link",
  "fieldset" : "Link to a media library item",
  "config" : {
    "select" : "media",
    "placeholder" : "Link to a media library item"
  }
}
    

Reference

type

string

Link

fieldset

string

a user-friendly field label

config

object

objects listed below

config

placeholder

string

user-friendly placeholder into the field

select

string

filters the link type: web, document, media

masks

array

only for config "select" : "document"
filters the document list depending on the custom types

tags

array

only for config "select" : "document"
filters the document list depending on the tags

Query blog posts from a given author (author being a Link in the blog-post custom type):

Copy
      var authorDocId = req.params.authorId;
api.query([
  prismic.Predicates.at("document.type", "blog-post"),
  prismic.Predicates.at("my.blog-post.author", authorDocId)
], { pageSize : 10 }).then(function(response) {
  // response.results is the list of blog posts from the requested author
});
    
Copy
      $response = $api
    ->query(
        Predicates::at("document.type", "blog-post"),
        Predicates::at("my.blog-post.author", $authorDocId))
    ->submit();

    
Copy
      Response response = api.query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
).submit();
    
Copy
      Response response = api.Query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
).Submit();
    
Copy
      response = api.query([
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
])
    

Orderings

Link fields cannot be used to order results.

Retrieving Additional Information

To prevent having to perform multiple queries, you can use fetchLinks to retrieve fields from the linked documents. It can only be used on simple types such as Text, Date, Timestamp and Number. StructuredText are also supported but only the first bloc will be returned, as a Text type.

Copy
      // Use fetchLinks to request additional fields in linked documents
api.getSingle('post',
  {'fetchLinks': 'author.name'}
).then(function(document) {
  var author = document.getLink('post.author');
  // Query linked document like a top-level document
  var authorName = author.getText('author.name');
});
    
Copy
      // Use fetchLinks to request additional fields in linked documents
$response = $api->query(
    [Predicates::at("document.type", "blog-post"), Predicates::at("my.blog-post.author", $authorDocId)],
    ["fetchLinks" => "author.name"]
);
$document = $response->getResults()[0];
$author = $document->getLink("blog-post.author");
// Query linked document like a top-level document
$authorName = $author->getText("author.name");

    
Copy
      // Use fetchLinks to request additional fields in linked documents
Response response = api.query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
).fetchLinks("author.name").submit();
Document doc = response.getResults().get(0);
// Query linked document like a top-level document
Fragment.DocumentLink author = doc.getLink("blog-post.author");
String authorName = author.getText("author.name").getValue();
    
Copy
      // Use fetchLinks to request additional fields in linked documents
Response response = api.Query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
).FetchLinks("author.name").Submit();
Document doc = response.Results.First;
// Query linked document like a top-level document
DocumentLink author = doc.GetLink("blog-post.author");
String authorName = author.GetText("author.name").Value;
    
Copy
      // Use fetchLinks to request additional fields in linked documents
response = api.query([
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.author", authorDocId)
]).FetchLinks("author.name")
doc = response.results[0]
// Query linked document like a top-level document
author = doc["blog-post.author"]
authorName = author["author.name"].value
    

Since the URL of internal document will depend on your URL scheme, a link resolver is necessary.

Copy
      a(href=prismicdoc.getLink('blog-post.source').url(ctx.linkResolver)) Click here!
    
Copy
      <a href="<?= $prismicdoc->getLink('blog-post.source')->getUrl($linkResolver) ?>">Click here</a>
    
Copy
      <a href="${prismicdoc.getLink("blog-post.source").getUrl(linkResolver)}">Click here</a>
    
Copy
      <a href="<%= prismicdoc["blog-post.source"].url(linkResolver) %>">Click here</a>