0

Is there a way in P&T Assets to output just the file's relative url path without the filename?

For instance, I'm trying to call a file's retina image.

This is the normal file output:

   {image_blog}
          {url}
   {/image_blog}

Which results in:

   /path/to/file/filename.jpg

But I'm looking to obtain this output instead:

   /path/to/file/filename@2x.jpg

I thought this could be accomplished with...

   {image_blog}
          {subfolder}{filename}@2x.{extension}
   {/image_blog}

... but this results in ...

   filename@2x.jpg

What is subfolder supposed to output if not /path/to/file/? Is there another way to grab the relative path?

2

Have you tried {url} or {server_path}? I suspect that {subfolder} (confusingly) refers subfolders of existing EE File Upload paths (i.e. subfolders that Assets recognizes, but EE does not).

| improve this answer | |
  • I never thought I'd use this sentence in my life, but here goes: "Sandwich is right on this one." Currently there is no great way of accomplishing what you need - subfolder refers to the folder structure within the source already. Without modifying Assets your best bet would be using another add-on to tweak the URLs or using PHP in this template on template output stage. – Andris Sevcenko Sep 16 '13 at 5:33
  • Yeah, I was going to use PHP to grab the relative path from the {url} or {serverpath}, I was just hoping I didn't have to. I work locally and push to production, so it kind of makes it a little more messy than I'd like. Oh well. Thanks! – xxx Sep 16 '13 at 20:45
0

Ended up using php to grab the relative path by subtracting {filename} from {url}.

<?php
    $url       = "{image_blog}{url}{/image_blog}";
    $filename  = "{image_blog}{filename}{/image_blog}";
    $extension = "{image_blog}.{extension}{/image_blog}";
    $needle    = $filename . $extension;
    $relative  = str_replace($needle,"",$url);
    $retina    = $relative . $filename . "@2x" . $extension;
    echo $retina;
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.