From 1939d13146f11fed8c0d2282742b91513e37a006 Mon Sep 17 00:00:00 2001 From: "Jason A. Crome" Date: Sun, 27 Oct 2024 20:24:08 -0400 Subject: [PATCH] (Mostly) completed template section. Still a few TODO items to resolve. --- lib/Dancer2/Manual.pod | 264 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 247 insertions(+), 17 deletions(-) diff --git a/lib/Dancer2/Manual.pod b/lib/Dancer2/Manual.pod index 1d4f43db3..dfb1f9017 100644 --- a/lib/Dancer2/Manual.pod +++ b/lib/Dancer2/Manual.pod @@ -636,6 +636,27 @@ Think of templates like mad lib games you played as a kid. You just need to fill in the blanks with the requested information, and the template makes the story come alive. +=head2 Views + +In Dancer2, "views" refer to the template files that define the structure +of the content presented to the users. Views are typically HTML files +with embedded placeholders that are dynamically filled with data when +rendered. + +=head3 How Views Work + +Suppose you have a template file called C: + +

[% ride_name %] Ride

+

Enjoy the thrilling [% ride_name %] ride at Danceyland!

+ +You can use this view in your route handler: + + get '/ride/:name' => sub { + my $ride_name = route_parameters->get('name'); + template 'ride' => { ride_name => $ride_name }; + }; + =head3 Example: Displaying a welcome message on a pretty banner get '/' => sub { @@ -661,8 +682,21 @@ In this example, the C route uses a template to display a welcome message. }; }; -- The `/map` route uses a template to display the park's map. -- The `/info` route uses a template to display various pieces of information about the park. +=over 4 + +=item * + +The C route uses a template to display a welcome message. + +=item * + +The C route uses a template to display the park's map. + +=item * + +The C route uses a template to display various pieces of information about the park. + +=back =head2 New Keywords @@ -674,29 +708,125 @@ data to pass to the template. template 'template_name', { key1 => 'value1', key2 => 'value2' }; -=head2 Supported template engines +=head2 Layouts + +Layouts in Dancer2 allow you to wrap views with a common structure, such +as a header, footer, or navigation bar, that remains consistent across +Danceyland. A layout is just another template that wraps around your page +content; it allows you to maintain a consistent look and feel across +multiple pages while rendering the dynamic content of each page within +the layout. + +=head3 Example: Implementing Layouts in Danceyland + +Consider Danceyland having a consistent navigation bar across all sections +of the site. You can use a layout for this. + + # views/layouts/main.tt + + + + + Danceyland + + +
+

Welcome to Danceyland

+ +
+ +
+ [% content %] +
+ +
+

© 2024 Danceyland

+
+ + + +C is a special variable for layouts; it is replaced by the +output from the C