[file_pathfromroot]
Description
Converts a relative path to a root path.
Parameters
none
Sample Usage
file_pathfromroot('../../images/foo.gif');
-> /images/foo.gif
Source Code
Click the "Download" button below to retrieve a copy of this tag,
including the complete documentation and sample usage shown
on this page. Place the downloaded ".inc" file in your
LassoStartup folder, restart Lasso, and you can begin using this
tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
define_tag(
'pathfromroot',
-namespace='file_',
-priority='replace',
-description='Converts a relative path to a root path.'
);
fail_if(
!params->size || !params->first->isa('string'),
-1,
'[file_pathfromroot] requires a file path as a parameter.'
);
local('in' = params->first);
if(#in->beginswith('/'));
return(#in);
else(#in->beginswith('../'));
local('steps' = #in->split('../')->size - 1);
local('out' = '/');
iterate(response_path->split('/'), local('i'));
loop_count > 1 ? #out += #i + '/';
loop_count == #steps ? loop_abort;
/iterate;
#out += #in;
return(#in);
else;
return(response_path + #in);
/if;
/define_tag;
Related Tags
Comments
none
Newest
Most Popular
Support tagSwap.net