*编辑: 我正在使用单页应用程序,通过使用“ui-route”,我设法在不加载新页面的情况下抛出不同的HTML页面。 所以我不需要在每个其他页面中包含主页面代码。 我希望我的问题现在更容易理解。
但是当我去另一个页面时,我想要徽标和菜单apear但不是引用
这是主页面代码:
<body>
<div style="text-align: center">
<img alt="adminPhoto" src="../Img/admin.png" width="300px"
height="300px">
</div>
<ul>
<li><a href="#/main"><img alt="Main" src="../Ico/main.png"></a></li>
<li><a href="#/manageCompanies"><img alt="Manage Companies"
src="../Ico/companies.png"></a></li>
<li><a href="#/manageCustomers"><img alt="Manage Customers"
src="../Ico/customers.png"></a></li>
</ul>
<div ui-view></div>
<div>
<blockquote style="margin-left: 30%;">
Welcome Admin!<br /> We welcome you to try out most convenient Admin
experience.<br /> Designed with the most advanced tools.<br /> Update,
Delete or Create your Companies and Customers - with only one click!<br />
<footer>
<cite>Daniel Liverant</cite>
</footer>
</blockquote>
</div>
</body>
我应该尝试什么方式?
答案 0 :(得分:0)
创建header.php或header .html文件。在那里粘贴您的菜单和徽标。然后在每个其他html文件中包含页面。
以下示例:
<强>的header.php 强>
<?php
include "header.php";
?>
<blockqoute> <!-- or not? -->
内容文件
require 'abstract_controller'
require 'action_controller'
require 'action_view'
require 'active_record'
# require any helpers
require './app/helpers/application_helper'
# active record only if data is here
require './app/models/widget'
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'db/development.sqlite3'
)
ActionController::Base.prepend_view_path "./app/views/"
# place data in view_assigns
view_assigns = {widgets: Widget.all}
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
av.class_eval do
# include any needed helpers (for the view)
include ApplicationHelper
end
# normal render statement
content = av.render template: 'widgets/index.xlsx.axlsx'
# do something with content, such as:
File.open("/tmp/with_runner.xlsx","w+b") {|f| f.puts content }
希望这有帮助!
答案 1 :(得分:0)
include(或require)语句获取指定文件中存在的所有文本/代码/标记,并将其复制到使用include语句的文件中。 当您想在网站的多个页面上包含相同的PHP,HTML或文本时,包含文件非常有用。
对于PHP,创建两个文件:
<强>的header.php 强>
<body>
<div style="text-align: center">
<img alt="adminPhoto" src="../Img/admin.png" width="300px"
height="300px">
</div>
<ul>
<li><a href="#/main"><img alt="Main" src="../Ico/main.png"></a></li>
<li><a href="#/manageCompanies"><img alt="Manage Companies"
src="../Ico/companies.png"></a></li>
<li><a href="#/manageCustomers"><img alt="Manage Customers"
src="../Ico/customers.png"></a></li>
</ul>
<div ui-view></div>
<强>的index.php 强>
<?php include 'header.php';?>
<div>
<blockquote style="margin-left: 30%;">
Welcome Admin!<br /> We welcome you to try out most convenient Admin
experience.<br /> Designed with the most advanced tools.<br /> Update,
Delete or Create your Companies and Customers - with only one click!<br />
<footer>
<cite>Daniel Liverant</cite>
</footer>
</blockquote>
</div>
</body>
您可以在网站的任何位置添加header.php。
答案 2 :(得分:0)
我所要做的就是在
中插入quoate代码<div ui-view> -code- </div>
就是这样。