Dreamweaver - 重复代码
我的网站中有大约 6 或 7 个页面包含重复的代码。它主要在主菜单和底部菜单中重复。我可以使用 Dreamweaver 中的某些功能同时编辑所有重复的代码吗?或者也许将主要代码放在所有页面导入的文件中?
I have around 6 or 7 pages in my site with repeated code. It's mostly repeated in the main and bottom menu. Can I use something in Dreamweaver to edit all the repeated code at the same time? Or maybe have the main code in a file that is imported by all the pages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种选择,具体取决于您可以使用的内容。
如果您使用服务器端技术,那么使用包含可能适合您。您需要创建一个包含通用代码的单独文件,并编辑所有页面,并将引用通用文件的服务器包含放在内容的位置。如何执行此操作取决于您可以使用的服务器语言。
Dreamweaver 还具有可能有用的非服务器功能:模板和库项目。模板旨在提供页面结构,并在页面内基于可编辑的模板(子页面)具有特定区域。库项目适用于在多个页面之间共享的代码块。您可以在模板中使用库项目,因此两者并不排斥。
根据您的问题,您似乎可以从图书馆项目中受益。在 Dreamweaver 中选择您想要共享的内容。
打开“资源”面板(“窗口”->“资源”),如果您的网站很大,这可能需要一些时间。面板打开后,切换到“资源”面板中的“库”类别(底部图标应该看起来像一本书)。在页面中选择共享内容,然后单击资源面板底部右下角左数第二个图标的“新建库项目”按钮(或转到“修改”->“库”->“将对象添加到库”)。所选代码应包含 HTML 注释,表明它现在是库项目。在“资源”面板中,您可以为内容命名。在其他页面上,您可以选择共享内容,然后在“资源”面板中单击面板左下角的“插入”按钮。根据需要重复(或者如果内容完全相同,您可以执行查找和替换,将内容更改为注释包装内容。
要编辑库项目,请在设计视图中选择它,然后打开属性检查器(窗口 -> 属性)并单击“打开”按钮(或在设计视图中右键单击库项目并选择“打开库项目”)进行编辑,当您保存库项目时,系统会询问您是否要更新。包含库项目的页面
将作为 .lbi 文件保存在站点根目录的库文件夹中
,但对于“静态”文件,库项目可能是一个。 nofollow
有关详细信息,请查看 Dreamweaver CS5 库项目帮助:http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7e49a.html
There are several options depending on what you have available to you.
If you're using a server side technology, then using an include could work for you. You'd need to create a separate file that contains the common code and edit all of your pages and place the server include that references the common file in the place of the content. How to do that will depend on which server languages you have available to you.
Dreamweaver also has to non-server based capabilities that may be useful: templates and library items. Templates are meant to provide the structure for a page and have specific areas within a page based on the template (child page) that are editable. Library items are meant for blocks of code that are shared between multiple pages. You can use library items within templates, so the two aren't exclusive.
Based on that you have in your question, it appears that you may benefit from a library item. In Dreamweaver select the content you want shared.
Open the Assets panel (Window -> Assets), this may take a bit of time if you have a large site. Once the panel is open, switch to the Library category in the Assets panel (should be the bottom icon looks like a book). In your page select the shared content, then click the New Library Item button at the bottom of the assets panel second from left icon on the bottom right (or go to Modify -> Library -> Add Object to Library). The selected code should be wrapped with HTML comments indicating that it is now a library item. In the Assets panel you can give the content a name. On your other pages you can select the shared content and then in the Assets panel click the Insert button on the bottom left of the panel. Repeat as necessary (or if the content is exactly the same, you may be able to do a find and replace to chane the content into the comment wrapped content.
To edit a library item, select it in design view, and then open the Property Inspector (Window -> Properties) and click the Open button (or right click on the library item in design view and select Open Library Item). Make your edits and when you save the library item you should be asked if you want to update the pages that have the library item on it.
Library items are saves as .lbi files in a Library folder at the root of your site.
Many folks prefer server includes over library items, but for "static" files, Library items may be an acceptable solution.
For more info, check out the Dreamweaver CS5 help for library items: http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7e49a.html
我有同样的问题。结果我创建了powershell脚本Update-Lbi。
I had a same problem. As result I have created the powershell script Update-Lbi.