[英](Umbraco) Can get text but not image from a subnode to homepage
I'm trying to get text and image from articles in the subsection "Featured" (Home/Featured/Article1, 2,...,N) but I don't get image. 我正在尝试从“功能”小节(首页/功能/ Article1,2,...,N)中的文章中获取文本和图像,但没有图像。 This is the code that works fine getting text from every article that is inside the 'Featured' Node. 这是从“功能”节点内的每篇文章中获取文本的代码。
<xsl:if test="position() < $maxItems">
<h3><a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="newsTitle"/>
</a>
</h3>
<strong><xsl:value-of select="intro"/></strong>
<br/>
<small>
A: <xsl:value-of select="umbraco.library:FormatDateTime($currentPage/@updateDate, 'MMMM d, yyyy')"/>
Por: <xsl:value-of select="author"/>
</small>
</xsl:if>
It works just fine. 它工作正常。 But I cannot get images from an article. 但是我无法从文章中获取图像。 I'm trying this way, among others: 我正在尝试这种方式,其中包括:
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="count(./* [@isDoc]) > 0">
<img src="{concat(substring-before(./*/thumbnail,'.'), '_thumb.jpg')}"/>
</xsl:if>
</a>
I don't know what to do here, I'm using 'Upload' property for an element and also with 'MediaPicker' (alias: 'thumbnail'), so, I've been testing with these property types but didn't get anything yet. 我不知道该怎么办,我正在为元素使用“ Upload”属性,还与“ MediaPicker”(别名:“ thumbnail”)一起使用,因此,我一直在测试这些属性类型,但是没有得到任何东西。 I just want to put the image (if exists) of the article next to text retrieved from a childnode to homepage. 我只想将文章的图像(如果存在)放在从子节点检索到首页的文本旁边。
I'll appreciate your help. 多谢您的协助。 Thanks in advance! 提前致谢!
[Umbraco 6.1.3] [Umbraco 6.1.3]
here's an example: 这是一个例子:
<xsl:variable name="mediaId" select="number($currentPage/mediaId)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
</xsl:if>
</xsl:if>
How to use umbraco.library GetMedia in XSLT 如何在XSLT中使用umbraco.library GetMedia
I think the error is that you need to select a property, not a node. 我认为错误是您需要选择一个属性,而不是一个节点。 You are using the @isDoc attribute, so no properties will be selected. 您正在使用@isDoc属性,因此将不会选择任何属性。
As mentioned, "thumbnail" is a property on a node (assuming only 1 thumbnail here) of datatype "Upload" (saves value of a path as a string): 如前所述,“缩略图”是数据类型“上传”(将路径值另存为字符串)的节点(此处仅假设1个缩略图)上的属性:
<xsl:if test="string-length(./thumbnail) > 0">
<a href="{umbraco.library:NiceUrl(@id)}">
<img src="{concat(substring-before(./thumbnail,'.'), '_thumb.jpg')}"/>
</a>
</xsl:if>
Or with the "media picker" datatype (saves the nodeid of the media-item as an int): 或使用“媒体选择器”数据类型(将媒体项目的节点ID保存为int):
<xsl:if test="string-length(./thumbnail) > 0">
<xsl:variable name="image" select="umbraco.library:GetMedia(./thumbnail,0)"/>
<a href="{umbraco.library:NiceUrl(@id)}">
<img src="{concat(substring-before($image/umbracoFile,'.'), '_thumb.jpg')}"/>
</a>
</xsl:if>
Since the other code that is posted is working fine, and it is not using $currentPage, I assume that this code is wrapped in a template or you are iterating over a set of nodes. 由于发布的其他代码运行正常,并且未使用$ currentPage,因此我假定此代码包装在模板中,或者您要遍历一组节点。
I would also put the link element inside the if statement and check whether a thumbnail is available or not before creating a link, just to avoid empty link elements. 我还将链接元素放在if语句中,并在创建链接之前检查缩略图是否可用,以避免空链接元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.