创建布局模板速度

时间:2018-01-12 21:10:28

标签: html templates velocity

我想创建一个默认模板,其中包含所有布局内容,例如html页面的头部和主体。但是我无法让它发挥作用。我搜索过它,但所有使用过的解决方案都不适用于我!

我的控制器:

path("/", () -> {
            get("", (req, res) -> {
                return new ModelAndView(new HashMap<>(), "views/menu.vm");
            }, velocityTemplateEngine);
        });

main.vm:

#macro(mainLayout)
<html>
<head>
   <script></script>
</head>
<body style="background-color: #2a2730">
<div class="content-container">
    <p>$!bodyContent</p>
</div>
</body>
</html>
#end

menu.vm

#@mainLayout()
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Kicker</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="/">Home</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       role="button" aria-haspopup="true" aria-expanded="false">Player <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="/player/list">Players list</a></li>
                        <li><a href="/player/new">New Player</a></li>
                        <li role="separator" class="divider"></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       role="button" aria-haspopup="true" aria-expanded="false">Match <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="/match/list">Match list</a></li>
                        <li><a href="/match/new">New Match</a></li>
                        <li role="separator" class="divider"></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                       role="button" aria-haspopup="true" aria-expanded="false">Season <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="/season/list">Season list</a></li>
                        <li><a href="/season/new">New Season</a></li>
                        <li role="separator" class="divider"></li>
                    </ul>
                </li>
                <li><a href="/match/dashboard">Dashboard</a></li>
                <li><a href="/stats">Statistics</a></li>
            </ul>
        </div>
    </div>
</nav>
#end

任何帮助我都会很开心

0 个答案:

没有答案