I needed to open a static page in a pop-up window. For static pages we have a handy controller Pages but I wanted to use a different layout for each page and do it in a flexible way.
The magic of my solution is in three lines of code in AppController (app/app_controller.php). I simplify the code for the sake of clarity:
-
span class=”st0″>’layout’‘layout’];
-
}
-
}
-
}
I created a file /app/views/layouts/popup.ctp that contains only:
And I call the static page as:
-
http://test.com/pages/termsOfMembership/layout:popup
Which is created using this call:
-
span class=”st0″>’Terms of Membership’‘controller’ => ‘pages’, ‘action’ => ‘termsOfMembership’, ‘layout’ => ‘popup’‘default’‘onclick’ => "window.open(this.href);")
-
),
With this setting in my /app/config/routes.php:
-
Router::connect(‘/pages/*’‘controller’ => ‘pages’, ‘action’ => ‘display’));
That Router setting is redundant if you use urls that look like this:
-
http://test.com/pages/display/termsOfMembership/layout:popup
Then you also have to use a different call to the Router::url():
-
span class=”st0″>’controller’ => ‘pages’, ‘action’ => ‘display’, ‘termsOfMembership’, ‘layout’ => ‘popup’)