将动态内容添加到代码点火器中的模板
我正在尝试将 HTML/CSS 文件转换为模板。我寻求帮助,但在那篇文章中我没有收到任何建议,但我试图找到一种创建模板的方法。我在做这件事时遇到了一些小问题。我的控制器有 main.php 文件,它是网站的主页,我已经注册了页眉、页脚和其余部分保持不变,除了页面加载时主要内容发生变化。
有以下模板:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?= $title ?></title>
<style type="text/css" >
@import url('<?=base_url()?>/includes/front.css');
@import url('<?=base_url()?>/images/');
</style>
</head>
<body>
<div id="container">
<div id="header">
<?= $logo ?> <!--This is an image tag to display the image on the template -->
<?= $topnav ?>
</div>
<div id="menubar">
<?= $menulist ?>
</div>
<div id="maincontent">
<?= $flashcontent ?>
<?= $resources ?>
<?= $registerForm ?>
</div>
<div id="footer">
<div>
<?= $footertable1 ?>
</div>
</div>
</div>
</body>
</html>
我在视图文件夹中
div id = 主要内容
这是当网站加载时会发生变化的 div 标签。在我的模板中,我包含了 <
<?= $flashcontent ?> <?= $resource ?> and <?= registerForm ?>
flashcontent 和资源应该位于主页中,并且当我在主页中单击注册时应该显示 registerForm。我一直在阅读代码点火器中的模板用户指南,但我无法理解如何使其动态化。请帮助我解决这个问题。
这是config文件夹中的template.php。
$template['active_group'] = 'default';
$template['default']['template'] = 'template.php';
$template['default']['regions'] = array(
'title',
'logo' => array(
'content' => array(''),
'name' => 'Logo',
'wrapper' => '<img>',
'attributes' => array('id' => 'logo')
),
'topnav' => array(
'content' => array(),
'name' => 'Topnav',
'wrapper' => '<div>',
'attributes' => array('id' => 'topnav', 'class' => 'topnav')
),
'menulist' => array(
'content' => array('<li>
<a href="#"> Home </a>
<a href="#"> Generator </a>
<a href="#"> News </a>
<a href="#"> Forum </a>
<a href="#"> About </a>
<a href="#"> Feedback </a>
</li>'),
'name' => 'Menulist',
'wrapper' => '<ul>',
'attributes' => array('class' => 'menulist')
),
'flashcontent' => array(
'content' => array(''),
'name' => 'Flashcontent',
'wrapper' => '<div>',
'attributes' => array('id' => 'flashcontent')
),
'resources' => array(
'content' => array(''),
'name' => 'Resources',
'wrapper' => '<div>',
'attributes' => array('id' => 'resources')
),
'registerForm' => array(
'content' => array(),
'name' => 'Registerform',
'wrapper' => '<div>',
'attributes' => array('id' => 'registerForm')
),
'footertable1' => array(
'content' => array('<ul>
<li> <a href="../main">Home</a>
<a href="#">News & Events</a>
<a href="#">Forum</a>
<a href="#">About us</a>
<a href="#">Contact us</a>
<a href="#">Terms of use</a>
<a href="#">Privacy policy</a>
<a href="#">Site map</a>
</li>
</ul>'),
'name' => '',
'wrapper' => '<div>',
'attributes' => array('id' => 'footertable1')
)
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;
提前致谢。
I am trying a HTML/CSS file to convert to a template. I asked for help but I didn't receive any suggestions in that post yet I tried to figure out a way to create a template. I am having few glitches in doing that. My controller has main.php file which is the main page of the website, and I have register where the header, footer, and rest remain same except that main content changes when the page loads.
I have the following template in the views folder:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><?= $title ?></title>
<style type="text/css" >
@import url('<?=base_url()?>/includes/front.css');
@import url('<?=base_url()?>/images/');
</style>
</head>
<body>
<div id="container">
<div id="header">
<?= $logo ?> <!--This is an image tag to display the image on the template -->
<?= $topnav ?>
</div>
<div id="menubar">
<?= $menulist ?>
</div>
<div id="maincontent">
<?= $flashcontent ?>
<?= $resources ?>
<?= $registerForm ?>
</div>
<div id="footer">
<div>
<?= $footertable1 ?>
</div>
</div>
</div>
</body>
</html>
In the
div id = maincontent
This is the div tag which would be changing when a site loads. In my template I have included <
<?= $flashcontent ?> <?= $resource ?> and <?= registerForm ?>
The flashcontent and resources are supposed to be in the main page and registerForm is supposed to be shown when I click on register in the main page. I have been reading the template user guide in the code igniter but I am unable to understand how to make this dynamic. Please help me in getting over this issue.
This is the template.php in config folder.
$template['active_group'] = 'default';
$template['default']['template'] = 'template.php';
$template['default']['regions'] = array(
'title',
'logo' => array(
'content' => array(''),
'name' => 'Logo',
'wrapper' => '<img>',
'attributes' => array('id' => 'logo')
),
'topnav' => array(
'content' => array(),
'name' => 'Topnav',
'wrapper' => '<div>',
'attributes' => array('id' => 'topnav', 'class' => 'topnav')
),
'menulist' => array(
'content' => array('<li>
<a href="#"> Home </a>
<a href="#"> Generator </a>
<a href="#"> News </a>
<a href="#"> Forum </a>
<a href="#"> About </a>
<a href="#"> Feedback </a>
</li>'),
'name' => 'Menulist',
'wrapper' => '<ul>',
'attributes' => array('class' => 'menulist')
),
'flashcontent' => array(
'content' => array(''),
'name' => 'Flashcontent',
'wrapper' => '<div>',
'attributes' => array('id' => 'flashcontent')
),
'resources' => array(
'content' => array(''),
'name' => 'Resources',
'wrapper' => '<div>',
'attributes' => array('id' => 'resources')
),
'registerForm' => array(
'content' => array(),
'name' => 'Registerform',
'wrapper' => '<div>',
'attributes' => array('id' => 'registerForm')
),
'footertable1' => array(
'content' => array('<ul>
<li> <a href="../main">Home</a>
<a href="#">News & Events</a>
<a href="#">Forum</a>
<a href="#">About us</a>
<a href="#">Contact us</a>
<a href="#">Terms of use</a>
<a href="#">Privacy policy</a>
<a href="#">Site map</a>
</li>
</ul>'),
'name' => '',
'wrapper' => '<div>',
'attributes' => array('id' => 'footertable1')
)
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您使用的是 CMS 还是自定义数据库?动态元素从何而来?
制作动态元素的基础知识如下:
在 html 上方:
然后在 html 中:
Are you using a CMS or a custom database? Where are the dynamic elements coming from?
The basics for making a dynamic element are as follows:
Above your html:
Then in your html:
您似乎正在使用Colin Williams 模板库。
我没有看过太多,但请阅读@ http:// /williamsconcepts.com/ci/codeigniter/libraries/template/reference.html#manipulation
编辑
(再次,假设您正在使用模板库,我认为您是),
您的模板中有一个区域
content
。您有一个名为registerForm
的视图,其中仅包含表单。在用于注册的
控制器方法
中,您只需执行以下操作:$this->template->write_view('content', 'registerForm');
该库将将视图
registerForm
的内容加载到content
区域。显然,您可以拥有任意多个区域,但模板库允许您定义您希望显示任何内容的区域(区域),然后将 HTML 或视图直接输出到该区域。
要么我误解了,但我认为我无法解释比这更简单的事情。这些文档也相当不错。
编辑第二个
这是我不久前使用此库完成的项目中的示例方法。
现在,当我访问 mysite.com/welcome/index 时,我的 HTML 模板将显示我在该方法中编写的内容。
我的 HTML 模板看起来有点像:
我的 config/template.php 文件看起来像这样:
template/master
引用我的视图文件夹 (template/master.php) 中的一个文件,其中包含我的布局(如多于)。Looks like you're working with Colin Williams Template library.
I haven't looked at it too much but take a read @ http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html#manipulation
Edit
(Again, assuming you are using the template library I think you are),
You have a region
content
in your template. You have a view calledregisterForm
which contains just the form.In your
controller method
for register, you simply have to do:$this->template->write_view('content', 'registerForm');
The library will load the content of the view
registerForm
in to thecontent
region.You can have as many regions as you like, obviously, but the template library allows you to define an area (a region) that you want any content to appear, and then outputs your HTML or views directly in to the region.
Either I misunderstand but I don't think I can explain it much simpler than this. The docs are rather good as well.
Edit the second
Here's a sample method from a project I did a while back using this library.
now when I access
mysite.com/welcome/index
my HTML template will be displayed with the content I wrote in the method.My HTML template looks a little like:
My config/template.php file looks like this:
template/master
refers to a file in my views folder (template/master.php) which contains my layout (as above).使用
uri_segment
控制您的动态内容。在您的
main.php
中:<前><代码>uri->segment(1) === false) {
$template['registerForm'] = $this->load->view('表单/注册');
}
//...
?>
单击时使用 JavaScript 加载新页面。在
main.php
中创建一个简单的函数,仅加载该表单模板并通过 ajax 显示该表单。Use
uri_segment
to control your dynamic content.In your
main.php
:Use JavaScript to load new page when clicked. Make a simple function in
main.php
just to load that form template and show that form via ajax.