简体   繁体   English

模板(.tpl)中的模板smarty

[英]Template in Template (.tpl) smarty

hey, Since a few weeks I'm try to program a PHP-Application with the smarty template solution. 嘿,几个星期后,我尝试用智能模板解决方案编写PHP应用程序。 Now a easy question for all professionals: How can I get a Template in a Template ? 对所有专业人士来说,这是一个简单的问题:如何在模板中获取模板? One example: index.php (page.tpl) include my login.php (login.tpl) 一个例子:index.php(page.tpl)包括我的login.php(login.tpl)

In the smarty documentation I have found this function: {include file="$tpl_name.tpl"} 在smarty文档中,我找到了这个函数: {include file="$tpl_name.tpl"}

But where is my login.php controller ? 但是我的login.php控制器在哪里? When this function include the login.tpl file, I have only HTML code or ? 当这个函数包含login.tpl文件时,我只有HTML代码或?

Can someone explain me this or give me a sample / tutorial ? 有人可以解释一下这个或者给我一个示例/教程吗?

Sorry for my bad english 对不起,我的英语不好

best regards 最好的祝福

That code is exactly what you want. 那段代码正是你想要的。 It will let you include another smarty template from within a template. 它将允许您在模板中包含另一个智能模板。

<html>
<head>
  <title>{$title}</title>
</head>
<body>
{include file='login.tpl'}

All variables available to the original template, are available to the template you just included. 原始模板可用的所有变量都可用于刚刚包含的模板。

Im not sure what you're saying about only having HTML code, maybe you're wanting this function instead: 我不确定你所说的只有HTML代码,也许你想要这个功能:

{include_php file='/path/to/login.php'}

Basically the login.tpl file in your case has to be an ordinary Smarty template (so it may contain html tags as well as Smarty tags). 基本上你的case中的login.tpl文件必须是一个普通的Smarty模板(因此它可能包含html标签以及Smarty标签)。 You can't include another controller from Smarty. 你不能包括Smarty的另一个控制器。

As far as I understand, you want to add login functionality to your index page. 据我所知,您希望在索引页面中添加登录功能。 This can be done in the following way: 这可以通过以下方式完成:
1) Include login.tpl to index.tpl, so you will have the login form included in your index page. 1)将login.tpl包含到index.tpl中,这样您就可以在索引页面中包含登录表单。
2) Specify different action for your login form, eg "login.php", so this login.php would be your login controller, which handles all login/logout logic. 2)为您的登录表单指定不同的操作,例如“login.php”,因此这个login.php将是您的登录控制器,它处理所有登录/注销逻辑。
3) After a user has successfully logged in, you can redirect them to the index.php (or any page you want). 3)用户成功登录后,您可以将它们重定向到index.php(或您想要的任何页面)。

Thus, you will have two separate controllers: main controller (responsible for index page) and login controller, responsible for logging in / logging out. 因此,您将拥有两个独立的控制器:主控制器(负责索引页面)和登录控制器,负责登录/注销。 login.tpl file in this case would be only a template containing some html and probably Smarty tags to render the login form. 在这种情况下,login.tpl文件只是一个包含一些html和可能是Smarty标签的模板来呈现登录表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM