0

I have worked on several ASP.NET applications recentely, and I was simply fascinated by the simplicity of it's HTML layouting.

Basiccaly there is one layout file, in which you write all the static HTML, CSS, JS, or really anything that will stay the same on all pages. Then, there are content pages, in which you only write the content of the pages.

So, for example you have an about.cshtml file that looks like this:

<h1>My name</h1>
<p>I am a junior web developer... etc</p>
<p>Contact me at example@gmail.com</p>

That's all the information needed for the about content page, when requested it will be inserted in the layout page.

So, my question:

Are there any ready-to-use tools to make this happen via html, javascript or php? I found myself implementing it via ajax calls, but that really is just a waste of resources, having to async load all the html files I have.

4

2 回答 2

1

对于纯 HTML,您可以使用static site generator. 例如:

在 Pelican 中,您有一个base.html模板,其中包含您希望出现在所有页面上的所有内容,因此页眉和页脚等(这些也可以被调用.header.html,然后在main.html模板中引用。

页面内容是用 Markdown 编写的,并放入名为postsor的文件夹pages中,然后你运行一个generate命令,它会html为你输出所有内容。

页面可以这样写:

{% extends "base.html" %}
{% block title %}{{ page.title }}{%endblock%}
{% block content %}
    <h1>{{ page.title }}</h1>
    {% import 'translations.html' as translations with context %}
    {{ translations.translations_for(page) }}

    {{ page.content }}
{% endblock %}

所以它扩展了base.html模板。

进一步阅读:

于 2013-06-26T09:45:25.123 回答
-1

查看Model-view-controller

于 2013-06-26T09:35:56.993 回答