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)
Generate 1 HTML out of Multiple DCR's
abhishek_gupta
Hi,
I have created a DCT, and then the users create several DCR's out of it which is saved in the Data folder. I have to create one HTML page out of all these DCR's. That is, by taking the content of all the DCR's in order, I have to create a HTML page with the help of a tpl. Is this possible and if yes how to achieve it. What I am aware of is that in a tpl we generally put dct.blah.blah. But in my case I have to get the content from the DCR.
Any suggestions..
Thanks,
Abhi
Find more posts tagged with
Comments
kss
You need to load dcr's into the tpl file with
iwpt_load_dcr() function or similar tag if outside <iw_perl>.
Hope this helps.
kunjal.
sunil_j
Hi Abhi,
You just need to use the iw_load_dcr("NAME OF THE DCR") and then assign this to some variable say "a" and then you can use similarly as a.blah blah.
Do use this tag under <iw_perl> section of the TPL.
Do let me know if you need further clarification on this.
Bye
Sunil
TeamSite Consultant
pawlr
# specify data directory to use
my $dir = '/default/main/branch/subbranch/WORKAREA/content/templatedata/contenttype/datatype/data';
# assign a directory handle (I'm using DH)
opendir DH, $dir;
# read contents of directory handle and assign them to variable $name
while ($name = readdir DH) {
# load all of thse dcrs
iwpt_load_dcr($name,'dcrlocal', 't');
}
# close the directory handle
closedir DH;
# load into array
@dcrs
= iwpt_dcr_list( 'dcr' );
# get count of all dcrs in directory
$dcr_count = scalar(
@dcrs)
;
# loop through and output values
iwpt_output( "<HTML>");
for ($count = 1; $count < $dcr_count; $count++) {
my $number = iwpt_dcr_value( 'dcr[$count].some_dcr_item' );
iwpt_output( $number . "\n");
}
iwpt_output( "</HTML>");
The wierd thing is that I cannot predict that the datarecords will load in the right ORDER.. if I rename or delete any datarecords it screws up the order, even though the filesystem _appears_ alphebatized...
So right now I'm trying to sort them using arrays, hashes, whatever and not having much luck.. if anyone has any more info on this problem, pls let me know if you're so inclined.. thx
Gregg Faus
Do you have a date field within each of your DCR's that you'd like to sort on? Or the timestamp of the file? etc... How do you want to sort it?
Adam Stoller
You will almost definitely want to use hashes - and a custom sort function -- something like: foreach (sort {$a{name} cmp $b{name}} (%hash)) { ... }
The problem you're having is that readdir() reads files in directory-entry order (which I believe is numerically sorted by inode, but I'm not sure) -- if you're on Unix - you can get the same effect by running: /bin/ls -f
(note lower-case 'f' not capital 'F')
--fish
(Interwoven Senior Technical Consultant)
Piers
This is exactly what I want, but I can't get it to run.
I'm running it from the CLT.
with something like
iwpt_compile.ipl -pt Y:/default/main/ba_www/WORKAREA/beta/templatedata/presentation/mytpl.tpl -ofile c:/a.html
a file is generated, but it's empty - it seems that the perl code is not reading the dcr's within the directory correctly - very difficultt to debug.
Am i missing something?
I have an urgent deadline on this - any help would be much appreciated, I apologise for the rush.
Thanks
Piers
Edited by Piers on 12/02/03 08:41 PM (server time).
Piers
Fixed my own problem.
here is the revised code.
<iw_perl>
# specify data directory to use
my $dir = "y:/default/main/wb_milo/WORKAREA/beta/templatedata/milo/news_page/data";
my $tmpdir="/templatedata/milo/news_page/data";
# assign a directory handle (I'm using DH)
opendir DH, $dir;
# read contents of directory handle and assign them to variable $name
while ($name = readdir DH) {
if($name !~ m|^\.|) {
# load all of thse dcrs
iwpt_load_dcr("$tmpdir/$name",'docroot', 't');
}
}
# close the directory handle
closedir DH;
# load into array
@dcrs
= iwpt_dcr_list( 'dcr' );
# get count of all dcrs in directory
$dcr_count = scalar(
@dcrs)
;
# loop through and output values
iwpt_output( "<HTML>");
for ($count = 1; $count < $dcr_count; $count++) {
my $number = iwpt_dcr_value( 'dcr[$count].Date' );
iwpt_output( $number . "\n");
}
iwpt_output( "</HTML>");
</iw_perl>
and how I'm currently excecuting it from CLT.
iwpt_compile.ipl -pt Y:/default/main/wb_milo
/WORKAREA/beta/templatedata/milo/news_page/presentation/news_home1.tpl -iw_i
nclude-location Y:/default/main/wb_milo/WORKAREA/beta/
Gery
Hi,
In the line code opendir DH, $dir; of your sample, where to define this Directory Handle (DH) or where to create it?
Thanks for the help.
Adam Stoller
The statement:
opendir DH, "$dir";
*does* define/create DH as a file handle for the contents of $dir.
RTFM: perldoc -f opendir
for more information.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Gery
I'm sorry, but I don't know how to do it. I don't know much about Perl
Can you give me a sample code of this definition?
Thanks.
Adam Stoller
You asked where DH got defined - I told you that it was defined/created within the
opendir
call that you yourself quoted - so that
is
sample code.
I'd suggest picking up one or more Perl books (O'Reilly's tend to be good - if you're relatively new to programming I'd recommend
Learning Perl
, if you have experience programming I'd recommend
Programming Perl
) and/or attending a class on Perl coding (Interwoven I believe still offers one, but other organizations do too) if you're planning to work with Perl code.
Perl comes with built-in documentation which you can access from the command-line / shell on your TeamSite server - as mentioned, you can find documentation regarding the
opendir
function by typing:
iwhome
/iw-perl/bin/perldoc -f opendir
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
getnaren
Hi,
could you please explain me on the following:
I have 50 dcrs in a news folder, and I want to loop through all of them and display
url with title and date from each on one single html file
Thanks in advance
jbonifaci
It's fairly straight forward using perl. Open the directory, get the list of DCRs, iterate through them and open/parse each one and output the title/date for each one. If you want more specific help, please post the script you have attempted this in and are having problems with.
~Jeff
JeremyH
In the PT faq (help files installed on every server) There is an example of slurping up an entire directory of PTs.
getnaren
Jeff,
I am trying to the following:
I have 50 Press releases in a folder generated from one template. and now I want to loop through all these dcrs and display by month and the dcr will have month entered in mm/dd/yyyy format
November
xyz Says Worldwide Mobile Phone Sales Increased 22 Percent in the Third Quarter of 2005
22 November 2005
xyz balsh balsh balshbalshbalsh
15 November 2005
sssss balsh balsh balshbalshbalshbalsh
13 November 2005
October
xyz Says Worldwide Mobile Phone Sales Increased 22 Percent in the Third Quarter of 2005
22 November 2005
xyz balsh balsh balshbalshbalsh
15 November 2005
sssss balsh balsh balshbalshbalshbalsh
13 November 2005
jbonifaci
Sounds good, go ahead and do it and let us know how it works. If you want to display them in a sorted order, read them into an array of hashes or hash of hashes first and then sort them date.
~Jeff
nipper
Did you even look at the samples Jeff mentioned ? This is pretty easy, however I
do not think anyone here will write it for you.
Set up a page for display, where the data you want displayed (date, title, etc)
insert a Perl block that will read a directory (or sub dirs if you have them), open
the DCR, grab the data you need, use iwpt_output to save it with any needed
HTML. Then close all tags outside the perl block.
Nidhi_Agrawal
Merge this code also with ur previous code for sorting the information..
<iw_pt>
<iw_perl>
<![CDATA[
%$MD_Hash=();
foreach $file(
@dcr)
{
%temp=();
$date=
"read date from ur dcr here"
;
$press_release_month=
"read month from dcr here"
;
$tempkey =$date;
$temp{$tempkey}="$press_release_content|$date";
if(exists $MD_Hash{$press_release_month})
{
$MD_Hash{$press_release_month}{$tempkey} = "$press_release_content|$date";
}
else
{
$MD_Hash{$press_release_month}={%temp};
}
}
closedir(REGIONDIR);
my $htmlstr;
$htmlstr="<table>";
my $forregionName="";
############Outer loop for sorting on Month#########################
foreach my $masterkey (sort keys %MD_Hash) {
chomp($masterkey);
############Outer loop for sorting on Date#########################
foreach my $key ( sort keys %{$MD_Hash{$masterkey}}) {
@splitedArray
=split(/\|/,$MD_Hash{$masterkey}{$key});
$htmlstr=$htmlstr."<tr><td>
@splitedArray[0]
'</td><td>
@splitedArray[1]<
;/td></tr>";
}
}
$htmlstr =$htmlstr."</table>";
iwpt_output($htmlstr);
]]>
</iw_perl>
</iw_pt>
Nidhi_Agrawal
U can use this code also...
@array
;
for($i=0;$i<
@dcr
;$i++)
{
$month="read month from dcr";
$date="read date from dcr here";
$content="read dcr content here";
@array[$i]=$month
.$date.$content;
}
@array=sort(
@array)
;
and then print the values from this array ...
This is simpler than hash
getnaren
What do u mean by
Merge this code also with ur previous code for sorting the information?
Nidhi_Agrawal
I hv given only perl part in my last post to u.
And how to load DCRs and accessing of contents from DCR is already given in others posts.
So you have to merge them .
Nidhi...
getnaren
Nidhi,
here is the tpl, please take a look at it and please let me know, if this is correct.
I have generated dcr as pr_11_22_2005, pr_11_29_2005, pr_10_29_2005,pr_10_30_2005 and when generated
these are pr_11_22_2005.html, pr_11_29_2005.html, pr_10_29_2005.html,pr_10_30_2005.html
I need url for the title and then the date