Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Nolan 6 posts 26 karma points
    Jul 09, 2010 @ 21:47
    Daniel Nolan
    0

    Resolving media urls in a virtual directory

    Hi all,

    I've got the following bit of XSLT for a marco.

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <div class="photo">
      <xsl:variable name="thumb" select="umbraco.library:GetMedia(photo,0)/Image" />
      <img style="border:0px;" src="{$thumb/umbracoFile}" />   
    </div>
    </xsl:for-each>

    My output for the image is:

    <img style="border:0px;" src="~/media/278/kevinp.jpg">

    How do I best resolve this to:

    /brochure/media/278/kevinp.jpg

    If i use umbraco.library.niceUrl(@id) for a page it works correctly.

    Thanks,

    Dan

  • Sascha Wolter 615 posts 1101 karma points
    Jul 09, 2010 @ 22:46
    Sascha Wolter
    0

    Hi Dan,

    I haven't had a look at Umbraco 4.5 yet and if the syntax changed, so I assume 4.0.* syntax will still work.

    Where is the image coming from? Has every one of your pages you are looping through a property with an alias 'photo', which is a media picker?

    If so, the following should work:

    <xsl:variable name="thumb" select="umbraco.library:GetMedia(data[@alias='photo'], 0)" />

    <img src="/brochure{$thumb/data[@alias='umbracoFile']}" alt="current()/@nodeName" />

    Other than nodes which have a virtual url media items refer to a physical file on the server, the address of which is stored in the data node with the alias 'umbracoFile'. 

    Hope that's what you were after,

    Sascha

  • Daniel Nolan 6 posts 26 karma points
    Jul 09, 2010 @ 22:58
    Daniel Nolan
    0

    Sascha,

    Your assumption is correct, 'photo' is a property of the pages i'm looking at in the for-each.

    I could certainly hardcode /brochure, and replace the ~, but I'd like to fetch the application name.

    If I were in a template or user control, for example, i could use

    <%= VirtualPathUtility.ToAbsolute("~/media/278/kevinp.jpg") %>

    Or simply set the img tage to runat="server".

    What I really is a way to do that in the xslt file.

    Thanks for your help,

    Dan

  • Sascha Wolter 615 posts 1101 karma points
    Jul 09, 2010 @ 23:26
    Sascha Wolter
    1

    Oh, I see, obviously you can't use the runat="server" tag in XSLT scripts.

    How bout this: create a custom XSLT extension dll with the following method:

    public static string GetVirtualMediaUrl(string mediaUrl){

    return VirtualPathUtility.ToAbsolute(mediaUrl);         //maybe you need to prefix this with '~'?

    }

    Then, in your xslt, you can use

    <img src="[yourPrefix]:GetVirtualMediaUrl($thumb/data[@alias='umbracoFile'])" />

    Otherwise I'm out of my depth I'm afraid... :)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 10, 2010 @ 10:10
    Dirk De Grave
    0

    Hi Daniel,

    Just for clarifying this, what changes did you make to a default installation? Since you're using a virtual directory, is that only for the media section, or for the complete umbraco installation? Especially in regard to using GetMedia(), cause it shouldn't make a difference if you're using a virtual directory, the GetMedia() should still fetch the correct path of it, right?

    Looking forward to your answer!

     

    Cheers,

    /Dirk

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Jul 10, 2010 @ 10:50
    Niels Hartvig
    0

    This is clearly an oversight in 4.5. Could anyone make a Codeplex work item that we need to include support for virtual urls in xslts then I'll add it to 4.5.1 when I'm back from vacation!

  • Daniel Nolan 6 posts 26 karma points
    Jul 10, 2010 @ 20:53
    Daniel Nolan
    0

    Thanks guys,

    To answer Dirk's questions,

    We've got the entire umbraco installation running in a virtual directory.

    umbracoHideTopLevelNodeFromPath is set to false in the web.config, but thats the only change I think might be relevant.

    Codeplex entry: http://umbraco.codeplex.com/workitem/28050

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Jul 20, 2010 @ 10:40
    Niels Hartvig
    0

    It's fixed and will be a part of the nightly build + v4.5.1. Macros (and items) will automatically resolve tilde based urls now - you don't need to change anything :)

    This means that you can also easily transfer from a virtual directory to a root path without any changes =)

  • Anders Burla 2560 posts 8256 karma points
    Jul 20, 2010 @ 10:52
    Anders Burla
    0

    @Daniel Nolan What steps did you do to get umbraco to run in a virtual directory?

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Jul 20, 2010 @ 10:54
    Niels Hartvig
    0

    @Anders Burla Johansen All you need to do is to assign the folder where Umbraco is running as an application in IIS. Umbraco 4.5.1 will have much better support for virtual directories. 4.5.0 have a number of virdir related bugs!

  • Anders Burla 2560 posts 8256 karma points
    Jul 20, 2010 @ 11:03
    Anders Burla
    0

    @Niels And thats the only thing? Not change anything in the web.config? Sounds as easy as using umbraco :)

    I will wait for 4.5.1 then :p

  • Chad 65 posts 129 karma points c-trib
    Mar 08, 2012 @ 07:37
    Chad
    0

    Sorry to ressurect this post but I've hit a very similar issue. Using 4.5.2, I'm finding that if the images were not initially saved in a virtual directory, then the ~ is stripped out.. intentionally:

    if (SystemDirectories.Root == string.Empty)
                                _relFilePath = _relFilePath.TrimStart('~');

     

    I've had a client loading a tonne of data in under a staging server which was not running under a Virtual Directory, and it now needs to be moved to a Virtual Directory for the live site and none of the image paths work correctly.

    Anyway got any ideas on resolving this?

Please Sign in or register to post replies

Write your reply to:

Draft