You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Jochen Lillich <jl...@teamlinux.de> on 2001/06/15 12:29:03 UTC

Separating code from layout

Hi,

with the Template thread going on and me looking for a suiting
solution of separating site code from site layout, I'd like to ask
you for examples how you do that with Embperl.

The embedding of Perl into HTML makes it possible to use Perl in the
way PHP does things. That's a great gain compared to CGI scripts, and
puts Perl in the same league as PHP. But here and there, code and
layout still are intermixed.

My goal is to make it possible to employ different teams for coding
and layout. There should be no big hassle with exchanging interface
information.

Even if I put the core functions into include files or encapsulate them
into objects, the .epl page still has to call them. This means, the web
designers have to integrate Perl calls defined by the developers into
their page layout.

It's the same with Embperls automatic table feature: While simple
constructs like loops can't be avoided (HTML::Template or Template
Toolkit use them, too), I'd rather not put the data gathering code for
the table in the same file.

TT seems like a viable solution to me. But is there a clean way of
integrating it with Embperl pages? Since Embperls reputation is very
good, I guess I'm lacking some vital information how Embperl can be
used for bigger web applications.

How do you achieve a real and thorough separation of content/code/layout? 
I'd be glad to learn from existing code: Are there downloadable examples
of real-world Embperl applications where this is done?

TIA,

        Jochen

-- 
----------------------------------------------------------------
 *Jochen Lillich*, Consultant/Trainer @ /TeamLinux GbR/
 Rheinstr. 26, 76676 Graben-Neudorf, Germany
 Tel. +49 7255 76784-12, Fax -50, http://www.teamlinux.de
----------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Separating code from layout

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

there are several possibilities:

1.) As Jack already wrote you can do the computing in a separate file and
call the output page via Execute. The file that does the computing could
either be another Embperl page or a Apache::Registry script or any other
Perl programm. You can pass variables via the param array. You could also
directly set the variables in a specifiy package and compile the output page
in that package. By this, you don't have to initialize the variables at the
top of the page. e.g.

$mypack::name = 'foo' ;

Execute ({inputfile => 'bar.epl', package => 'mypack'}) ;

Now your designer could simply write [+ $name +] to access the variable.

2.) You could write a modul that does your computing and imports variables
or functions into the output page. So the only thing you have to do is to
write

[- use MyModule ; -]

at the top of each page and now your designers can access all the variables
and functions you export, e.g. when you export a function called 'name' they
can write

[+ name +]

to print out the name.

You have more possibilites with Embperl 2.0:

3.) You can define your own tags, so your desgins may write

<name>

which will call a function in your module, which can now whatever it wants,
for example replace that tag with the name of who ever.

4.) You can define a TT like syntax for Embperl 2.0. In this case Embperl
behave similar to TT, but it's up to you which syntax you like to use in
which page, by simply callling Embperl with

Execute ({inputfile => 'bar.epl', syntax => 'TT'}) ;

you are able to switch the syntax. You can even switch the syntax inside a
page or add new syntaxs elements.

Hope this helps a little bit, let me know if you have further
questions/ideas. Especialy Embperl 2.0 is very powerfull in the direction.

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------

----- Original Message -----
From: "Jochen Lillich" <jl...@teamlinux.de>
To: <em...@perl.apache.org>
Sent: Friday, June 15, 2001 12:29 PM
Subject: Separating code from layout


> Hi,
>
> with the Template thread going on and me looking for a suiting
> solution of separating site code from site layout, I'd like to ask
> you for examples how you do that with Embperl.
>
> The embedding of Perl into HTML makes it possible to use Perl in the
> way PHP does things. That's a great gain compared to CGI scripts, and
> puts Perl in the same league as PHP. But here and there, code and
> layout still are intermixed.
>
> My goal is to make it possible to employ different teams for coding
> and layout. There should be no big hassle with exchanging interface
> information.
>
> Even if I put the core functions into include files or encapsulate them
> into objects, the .epl page still has to call them. This means, the web
> designers have to integrate Perl calls defined by the developers into
> their page layout.
>
> It's the same with Embperls automatic table feature: While simple
> constructs like loops can't be avoided (HTML::Template or Template
> Toolkit use them, too), I'd rather not put the data gathering code for
> the table in the same file.
>
> TT seems like a viable solution to me. But is there a clean way of
> integrating it with Embperl pages? Since Embperls reputation is very
> good, I guess I'm lacking some vital information how Embperl can be
> used for bigger web applications.
>
> How do you achieve a real and thorough separation of content/code/layout?
> I'd be glad to learn from existing code: Are there downloadable examples
> of real-world Embperl applications where this is done?
>
> TIA,
>
>         Jochen
>
> --
> ----------------------------------------------------------------
>  *Jochen Lillich*, Consultant/Trainer @ /TeamLinux GbR/
>  Rheinstr. 26, 76676 Graben-Neudorf, Germany
>  Tel. +49 7255 76784-12, Fax -50, http://www.teamlinux.de
> ----------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: Separating code from layout

Posted by Jack Cushman <jc...@avatartechnology.com>.
Hi,

The way we usually do it is with 2 embperl files -- 1 for code and one for
layout. The code file loads all the data and then calls the other.

For example:

index.epl:
[-
	use DBI;

	foreach $key (keys %fdat){
		#handle form input
	}

	#load database info...
	$name = #get name
	$date = #get date
	$size = #get size

	Execute('index.ht', $name, $size, $date);
-]

index.ht:
[-
	$name = $param[0]; #the user's name
	$size = $param[1]; #the user's shoe size
	$date = $param[2]; #last login date
-]
	<html>
	<body>
	</body>
	</html>


Given a file like index.ht, the designers never have any trouble creating
the layout and filling in [+ $name +] wherever the username should go.

--Jack

-----Original Message-----

Hi,

My goal is to make it possible to employ different teams for coding
and layout. There should be no big hassle with exchanging interface
information.

TIA,

        Jochen


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org