I modified it to use [$sub$]
<https://perl.apache.org/embperl/pod/doc/Embperl.-page-3-.htm#sect_7>
and [+ local $escmode = 0; $something +]
I get the following error:
ERR: 24: Error in Perl code: Undefined subroutine
&Embperl::__82::subroutinecalled at ...
*--- main.epl*
[- Execute("subroutine.epl"); -]
[$ while ( ($ID) = $sth->fetchrow) $] [- %opts = ();
$opts{ID} = $ID; $opts{title} = "Modal Title";
$opts{footer} = "Modal Footer"; $opts{frameSrc} =
"file.epl"; $opts{linkText} = 'Click Me to Open Modal';
subroutine(\%opts); -] [$ endwhile $]
*--- subroutine.epl*
[$ sub subroutine $] [- (%param) = %{$param[0]}; -]
<!-- trigger modal -->
<a id = "trigger_[+ $param{ID} +]" title = "[+
$param{title} +]" alt = "[+ $param{title} +]"
style = "cursor:pointer;" > [+ local $escmode = 0;
$param{linkText} +] </a>
<script> $('#trigger_[+ $param{ID} +]').click(function(){
var frameSrc = "[+ local $escmode = 0; $param{frameSrc} +]";
$('#iframe_[+ $param{ID} +]').attr("src",frameSrc); $('#modal_[+
$param{ID} +]').modal({show:true}) }); </script>
<!-- modal -->
<div class="modal fade pageWidth" id="modal_[+ $param{ID} +]"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div
class="modal-dialog pageWidth" role="document"> <div
class="modal-content"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> [+
$param{title} +] </h4> </div> <div
class="modal-body"> <iframe id="iframe_[+ $param{ID} +]"
src="" frameborder="0" height="400" class="pageFull"></iframe>
</div> <div class="modal-footer"> [+ $param{footer} +]
<button type="button" class="btn btn-default"
data-dismiss="modal">Close</button> </div> </div>
</div> </div> [$ endsub $]
On 8/25/2016 6:02 PM, Angus Lees wrote:
On Fri, 26 Aug 2016 at 08:37 Ed Grimm <e...@raytheon.com
<mailto:e...@raytheon.com>> wrote:
What you have is a slow version of an Embperl subroutine. Use an
actual Embperl subroutine instead. Use Execute at most once to
load it.
^ This. It's been a decade or two since I last wrote any Embperl
code, but I'm guessing you're being slowed down by Embperl having to
find and stat the 'template.epl' file to see if it has changed 500 times.
Wrap your template code in a [$sub$], Execute template.epl once at the
top somewhere (one file stat()) and import the new [$sub$] function,
then just call the sub like a regular perl function (no additional
stat() lookup) inside your loop. See the docs for [$sub$]
<https://perl.apache.org/embperl/pod/doc/Embperl.-page-3-.htm#sect_7>
As an aside, this construct:
[- $escmode = 0 -][+ $something +][- $escmode = 1 -]
Is much safer if written as the following, since you can't forget to
restore $escmode:
[+ local $escmode = 0; $something +]
- Gus
It's my understanding that generally, templates are done in
Embperl::Object. But when doing it that way, your template is
stored in your base Embperl::Object file, as Embperl code, rather
than having everything stored in a database. Of course, that has
the advantage that you don't need to pull 500+ rows from your
database to generate your page.
--
Ed Grimm
From: Donavon <d...@mycopanet.com <mailto:d...@mycopanet.com>>
To: "embperl@perl.apache.org <mailto:embperl@perl.apache.org>"
<embperl@perl.apache.org <mailto:embperl@perl.apache.org>>
Date: 08/25/2016 05:35 PM
Subject: EMBPERL: Calling Execute() multiple time per a page.
------------------------------------------------------------------------
I have a loop that is calling Execute() to load a EMBPERL page as
a template. This template sets up and contains a bootstrap modal
and some javascript . The page I'm using as a test calls the
template at least 500x.
This is really slowing down the loading of the page for the client.
Are there any suggestion for optimizing and / or speeding this up?
Thank You,
~Donavon_
__djlerman@yahoo.com_ <mailto:djler...@yahoo.com>
[$ while ( ($ID) = $sth->fetchrow) $]
[-
%opts = ();
$opts{ID} = $ID;
$opts{title} = "Modal Title";
$opts{footer} = "Modal Footer";
$opts{frameSrc} = "file.epl";
$opts{linkText} = 'Click Me to Open Modal';
Execute("template.epl", \%opts);
-]
[$ endwhile $]
*--- template.epl*
[-
(%param) = %{$param[0]};
-]
<!-- trigger modal -->
<a id = "trigger_[+ $param{ID} +]"
title = "[+ $param{title} +]"
alt = "[+ $param{title} +]"
style = "cursor:pointer;"
>
[- $escmode = 0; -][+ $param{linkText} +][- $escmode = 1; -]
</a>
<script>
$('#trigger_[+ $param{ID} +]').click(function(){
var frameSrc = "[- $escmode = 0; -][+ $param{frameSrc} +][-
$escmode = 1; -]";
$('#iframe_[+ $param{ID} +]').attr("src",frameSrc);
$('#modal_[+ $param{ID} +]').modal({show:true})
});
</script>
<!-- modal -->
<div class="modal fade pageWidth" id="modal_[+ $param{ID} +]"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog pageWidth" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">
[+ $param{title} +]
</h4>
</div>
<div class="modal-body">
<iframe id="iframe_[+ $param{ID} +]" src="" frameborder="0"
height="400" class="pageFull"></iframe>
</div>
<div class="modal-footer">
[+ $param{footer} +] <button type="button" class="btn
btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Message protected by MailGuard: e-mail anti-virus, anti-spam and
content filtering.
http://www.mailguard.com.au/mg
Report this message as spam
<https://console.mailguard.com.au/ras/1P7uDVpwwI/zbZIfBnhOSGGC3Q2arnxH/0.612>