(Umbraco) 可以从子节点到主页获取文本但不能获取图像 [英] (Umbraco) Can get text but not image from a subnode to homepage

查看:25
本文介绍了(Umbraco) 可以从子节点到主页获取文本但不能获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从精选"小节(主页/精选/文章 1、2、...、N)中的文章中获取文本和图像,但我没有获取图像.这是从精选"节点内的每篇文章中获取文本的代码.

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. This is the code that works fine getting text from every article that is inside the 'Featured' Node.

 <xsl:if test="position() &lt; $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>

我不知道在这里做什么,我对一个元素使用了上传"属性,还使用了MediaPicker"(别名:缩略图"),所以,我一直在用这些属性类型进行测试,但是还没有得到任何东西.我只想将文章的图像(如果存在)放在从子节点检索到主页的文本旁边.

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. 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!

[翁布拉科 6.1.3]

[Umbraco 6.1.3]

推荐答案

我认为错误在于您需要选择一个属性,而不是一个节点.您正在使用 @isDoc 属性,因此不会选择任何属性.

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.

如前所述,缩略图"是数据类型为上传"(将路径值保存为字符串)的节点(此处假设只有 1 个缩略图)上的属性:

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):

<xsl:if test="string-length(./thumbnail) > 0">
<a href="{umbraco.library:NiceUrl(@id)}">
<img src="{concat(substring-before(./thumbnail,'.'), '_thumb.jpg')}"/>
</a>
</xsl:if>   

或者使用媒体选择器"数据类型(将媒体项的 nodeid 保存为 int):

Or with the "media picker" datatype (saves the nodeid of the media-item as an 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>

由于发布的其他代码工作正常,并且没有使用 $currentPage,我假设此代码包含在模板中,或者您正在迭代一组节点.

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.

我还将链接元素放在 if 语句中,并在创建链接之前检查缩略图是否可用,以避免出现空链接元素.

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.

这篇关于(Umbraco) 可以从子节点到主页获取文本但不能获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆