0
votes

i am making a website in umbraco. In this i am rendering image using umbraco.library.getMedia method. Here i am facing a very strange behaviour of umbraco. Sometimes images get rendered and some times images do not render. I have analyzed xslt and i found that getMedia(nodeid,0)/umbracoFile does not return any thing when i get empty image src. If i publish any node or work somewhere in umbraco and then publish site, then i may found rendered images. It means that images randomly appears and disappears. It is totally conusing me, where is the fault. please help me.

I am posting code used to render image

<xsl:variable name="img1" select="umbraco.library:GetMedia($slideImg,'false')/umbracoFile" />
<xsl:variable name="img2" select="umbraco.library:GetMedia($slideImg,0)/umbracoFile" />

<xsl:choose>
        <xsl:when test="$img1!= ''">
                                <img src="{$img1}" alt="" style="display: block;"
                                title="{umbraco.library:GetXmlNodeById(@id)/imageTitle}" description="{umbraco.library:GetXmlNodeById(@id)/description}"/> 
                            </xsl:when>
                            <xsl:otherwise>


                                <img src="{$img2}" alt="" style="display: block;"
                                title="{umbraco.library:GetXmlNodeById(@id)/imageTitle}" description="{umbraco.library:GetXmlNodeById(@id)/description}"/> 

                            </xsl:otherwise>
                        </xsl:choose>
1

1 Answers

0
votes

From what i understand you are trying to display an image and but are not getting image displaying each time using your code above.

I have cloned you code above and refined it to the below, i have first checked whether the slideImg is equal to true using the currentPage variable with your value fixed to the end and if true continue to the code below. I have then created my variable in the if statement as i don't need it to be interrupted unless we have a image available. I have in the variable got the media file slideImg and displayed this image in the img src by fixing the /umbracofile to the end of the variable which will pull the images path through.

<xsl:if test="$currentPage/slideImg != 0">
  <xsl:variable name="img1" select="umbraco.library:GetMedia($currentPage/slideImg, 0)" />

    <img src="{$img1/umbracoFile}" alt="{$img1/@nodeName}" />

</xsl:if>

I hope this solves your problem. Apologies if this doesn't make too much sense i'm abit of a newbie to forums