【发布时间】:2019-05-18 04:27:40
【问题描述】:
目标:使用 Gatsby 渲染与节点关联的 Drupal 8 图像
我可以使用 GraphQL 查询很好地呈现默认的 Drupal 8 文章节点信息。我无法获取要呈现的默认图像字段 (field_image) - 它只是呈现图像的 url。所以我快到了,但肯定缺少一些基本的东西。请帮忙?
import React from "react"
import { Link, graphql } from "gatsby"
import Img from "gatsby-image"
const BlogPage = ({data}) => (
<div>
<h1>Know What Grinds My Gears?</h1>
{ data.allNodeArticle.edges.map(
(
{ node }) => (
<div>
#the next Img line doesn't work (renders nothing)
<Img fluid={ node.relationships.field_image.uri.url } />
<h3> { node.title } </h3>
<div dangerouslySetInnerHTML={{ __html: node.body.summary }} />
<Link to= { node.id } >read</Link>
#the next <figure> line doesn't work (renders correct url to image file)
<figure> { node.relationships.field_image.uri.url }</figure>
</div>
)
)
}
</div>
)
export default BlogPage
export const query = graphql`
query allNodeArticle {
allNodeArticle {
edges {
node {
id
title
body {
value
format
processed
summary
}
relationships {
field_image {
uri {
value
url
}
}
}
}
}
}
}
`
我做错了什么?
【问题讨论】:
-
node.relationships.field_image.uri.url是一个有效的网址吗?例如,您可以将其用作<img>的 href 属性吗? -
感谢您的评论。
node.relationships.field_image.uri.url给了我这个/sites/default/files/images/photo1.jpg这是正确的。我需要以某种方式在它前面加上../path-to-my-drupal-site才能正确提取图像,但我在gatsby-config.js中设置了路径,所以我仍然认为我只是没有通过 GraphQL 正确访问它......?
标签: image drupal graphql drupal-8 gatsby