Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
relative paths and TST
nipper
OK, I need to change TPL that was generating absolute paths (portal does not like it) so I need
to go to relative paths
Haven't seen anything in the tech library, so this is what I am thinking:
in the TPL, a perl script that parses the DCR path (DCR and generated HTML are supposed to be in the
same heirarchy) blah/templatedata/cat/type/data/path/DCR, for each level in path, $rel_path="../" and
then prepend this to the all the css, js, images, etc.
Is there an easier way ? Can I get the file name and path of the generated HTML in the TPL ?
TIA
Andy
Find more posts tagged with
Comments
Migrateduser
See the perldoc for TeamSite:
T::iw_perl
Unless I am misunderstanding your question, you are looking for iwpt_get_ofile_name()
Dwayne
You may also want to use
iwpt_get_flag_param('-iw_include-location')
which, under normal conditions, will give you the path to the top of the workarea, as you're likely to want to remove that from the front end of the iwpt_get_ofile_name() result.
--
Current project: TS 5.5.2/6.1 W2K
nipper
So here is what I did:
<iw_perl><![CDATA[
$path=iwpt_get_ofile_name('dirname');
$path =~ s|/.*/WORKAREA/||;
$levels = split (/\//,$path);
$index=1;
$rel_path ="";
while ($index < $levels){
$rel_path .= "../";
$index +=1;
}
]]> </iw_perl>
This calculated the number of directories from WORKAREA to the DCR and built up 1 less ../../
& then I changed:
href="/css/main.css"
to
href="{iw_value name='$rel_path'/}css/main.css"
works pretty well. If someone moves the HTML up or down, then it will break, not much you can do about that.
I did notice that when I ran my regen all (find . -name "*.html" -exec iwregen {} \; )
I got this complaint about my use of split:
Use of implicit split to
@_
is deprecated at (eval 10) line 70.
Not certain why, but it worked.
Thanks
Andy
Adam Stoller
Use of implicit split to
@_
is deprecated at (eval 10) line 70.
That's because you're assigning the result of split to a scalar - instead you should assign it to an array and simplify your code:
(my $path = iwpt_get_ofile_name('dirname')) =~ s|^.*?/WORKAREA/||;
my
@levels
= split('/', $path);
my $rel_path = '../' x (
@levels
- 1) ;
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
nipper
Fish,
Somehow I knew you would reply.
I was wondering about the delimiter for split, perldoc.com said split (/PATTERN/,...) so splitting using slash / as a
pattern is ugly. I should have tried another delimiter.
My Q is about the statement
my $rel_path = '../' x (
@levels
- 1) ;
so if
@levels
is 3, that will produce "../../" ?
what is that puppy called ?
Thanks again
Andy
Dwayne
perldoc.com said split (/PATTERN/,...) so splitting using slash / as a pattern is ugly. I should have tried another delimiter.
/
is only the
default
regex separator. You can use anything you like, provided you use the alternate form:
split (
m
|PATTERN|, ...)
(or whatever character you want where the
|
appears).
My Q is about the statement my $rel_path = '../' x (
@levels
- 1) ;
The 'x' is called the repetition operator. Is that what you were asking about?
--
Current project: TS 5.5.2/6.1 W2K
Adam Stoller
perldoc.com said split (/PATTERN/,...) so splitting using slash / as a pattern is ugly. I should have tried another delimiter.
/ is only the default regex separator. You can use anything you like, provided you use the alternate form:
split (m|PATTERN|, ...)
(or whatever character you want where the | appears).
Actually, split will accept either
/.../
or
'...'
without requiring the
m
pre-fix so, if you're splitting on
/
's you can just use
'
s.
My Q is about the statement my $rel_path = '../' x (
@levels
- 1) ;
The 'x' is called the repetition operator. Is that what you were asking about?
From the
perldoc perlop
documentation:
Binary "x" is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is enclosed in parentheses, it repeats the list. print '-' x 80; # print row of dashes
print "\t" x ($tab/8), ' ' x ($tab%8); # tab over
@ones
= (1) x 80; # a list of 80 1's
@ones
= (5) x
@ones
; # set all elements to 5
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Dwayne
Actually, split will accept either /.../ or '...' without requiring the m pre-fix so, if you're splitting on /'s you can just use 's.
I have to admit that I didn't know that. However, knowing it, I think I'll still stick with "normal" regex syntax (needing the
m
if using other than slash(
/
) as the separator. It seems cleaner and more consistent to me. But to each his own.
--
Current project: TS 5.5.2/6.1 W2K
Adam Stoller
For regex's where I'm using the =~ operator, I agree - I almost always use /, m!, or m| (/, s!, s|) - but for split() it seems reasonably clean to use '...' around the first parameter, and certainly better than doing /\/...\// :-)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com