Handling Dynamic Views Like CakePHP Layout

111 views
Skip to first unread message

Von Penaloza

unread,
Nov 4, 2014, 8:20:33 AM11/4/14
to tot...@googlegroups.com
I am new to totalJs and right now i can't clearly understand how it handles dynamic views. I've done many projects in CakePHP. Cake has a default layout which handles the main layout of the app.

It looks like this.

<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $this->fetch('title'); ?></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<!-- Include external files and scripts here (See HTML helper for more info.) -->
<?php
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
?>
</head>
<body>

<!-- If you'd like some sort of menu to
show up on all of your views, include it here -->
<div id="header">
    <div id="menu">...</div>
</div>

<!-- Here's where I want my views to be displayed -->
<?php echo $this->fetch('content'); ?>

<!-- Add a footer to each displayed page -->
<div id="footer">...</div>

</body>
</html>

This layout will handle all the contents of the controllers method Add User view. See code below

<div>
Add Users
<input type='text' name='username' />
<input type='submit' value='submit'/>
</div>

The layout is now can be use by any method of any controller. I know that totalJs has a default layout but does it has a feature-like cakephp's layout?

Thanks in advance and sorry for my very bad english.

Peter Širka

unread,
Nov 4, 2014, 1:02:33 PM11/4/14
to tot...@googlegroups.com
Hi Von,
yes, framework supports feature like cackephp.

_layout.html (you can create many layouts and you can change the layout like this @{layout('my-new-layout')})

<!DOCTYPE html>
<html>
<head>
    @{meta}
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=10" />
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=1024, user-scalable=yes" />
    <meta name="robots" content="all,follow" />

    <!-- Include external files and scripts here (See HTML helper for more info.) -->
    @{js('default.js')}
    @{css('default.css')}

</head>
<body>
    <!-- If you'd like some sort of menu to show up on all of your views, include it here -->
    <div id="header">
        <div id="menu">...</div>
    </div>

    <!-- Here's where I want my views to be displayed -->    
    <div id="content">@{body}</div>

    <!-- Add a footer to each displayed page -->
    <div id="footer">
        @{section('footer')}
    </div>
    
</body>
</html>

Some view e.g. homepage.html (A below view replaces @{body} markup):

<div>
Add Users
<input type='text' name='username' />
<input type='submit' value='submit'/>
</div>

Bad english ---> I have a similar problem but I understand you :-)
Thanks.

If you need help, contact me or use Gitter (chat) or GitHub.
Thanks.

Von Penaloza

unread,
Nov 5, 2014, 1:58:37 AM11/5/14
to tot...@googlegroups.com
Thanks for the replay peter...so if i create a user view in views/users/add.html does the content of add.html will be shown in @body part of the layout??

Peter Širka

unread,
Nov 5, 2014, 2:02:37 AM11/5/14
to tot...@googlegroups.com
Yes, but you must create a "user" controller because framework reads views like this:

view/CONTROLLER-NAME/VIEW-NAME.html

Only one exemption: "default" controller:
view/VIEW-NAME.html

Thanks.

Von Penaloza

unread,
Nov 5, 2014, 2:13:46 AM11/5/14
to tot...@googlegroups.com
Ok... thanks again peter.. I'm excited to work on this framework...
Reply all
Reply to author
Forward
0 new messages