我可以将CSS作为ModX资源进行管理吗? [英] Can I manage my CSS as ModX Resources?

查看:93
本文介绍了我可以将CSS作为ModX资源进行管理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与ModX Revolution管理器一起工作,并且想知道是否可以将CSS转换为ModX资源而不是文件.我还想利用模板及其变量.那可能吗?这样做有什么弊端?除了我认为的那些以外,还有什么优点吗?

I've been working with the ModX Revolution manager, and was wondering if I can turn my CSS into ModX Resources rather than files. I'd also like to utilize Templates and their variables. Is that possible? What are the drawbacks of doing so? Are there any advantages (aside from the ones I think below)?

我之所以愿意这样做,是因为我将多个CSS页面与@import语句一起使用,以更好地面向对象定向CSS.如果我可以直接在ModX中执行此操作,则可以节省上传和同步的时间.

The reason I would prefer this is that I use several CSS pages with the @import statement to object orient my CSS a little bit better. If I could do this directly in ModX, it would save me uploads and syncing.

推荐答案

在ModX的早期版本(Evo和Revo)中,您不得不经历一些技巧.现在有了2.2.2pl,只需很少的技巧就可以实现.用于执行此操作的信息稀疏且不准确.操作方法如下:

In previous versions of ModX (Evo and Revo), you used to have to go through tricks. Now with 2.2.2pl, it is possible with very few tricks. The information to do this is sparse and inaccurate any more. Here's how you do it:

  1. 创建一个新模板.我命名为我的CSS样式表. (就这么简单)

  1. Create a new Template. I named mine CSS Stylesheet. (Simple as that)

对于内容,只需放入[[*content]].

创建CSS页面

  1. 创建一个新资源.随便命名吧.

  1. Create a new resource. Name it whatever you would like.

添加您的别名.确保不要在末尾添加.css. ModX应该为您执行此操作.

Add your alias. Make sure you do not add the .css at the end. ModX should do this for you.

现在,确保您的新页面为published.您可能还想hide from menus.

Now, make sure your new page is published. You may also want to hide from menus.

添加您的CSS代码.没有有趣的把戏……只需像往常一样复制并粘贴.

Add your CSS code. No funny tricks... Just copy and paste it like you normally would.

测试样式表

只需直接导航到您的新页面即可,就像它是html文档一样.不要忘记.css而不是.html.如果您看到CSS代码,那么您就成功了.

Test the Stylesheet

Simply navigate directly to your new page as if it were an html document. Don't forget the .css instead of .html. If you see the CSS code, then you've succeeded.

这是棘手的部分.您将无法使用<link rel=></link>.

This one is the tricky part. You won't be able to use the <link rel=></link>.

  1. 只需转到您的<head>元素.添加以下代码:

  1. Simply go to your <head> element. Add the following code:

<style type="text/css"> @import url("); </style>

<style type="text/css"> @import url(""); </style>

测试

url("");内,只需将URL放置到您的新资源中即可.

Inside the url("");, just place the url to your new resource.

优势

除了保存上载和下载外,您现在还可以使用任何ModX工具编辑CSS.此外,还有其他一些好处:

Advantages

Aside from the saving the uploading and downloading, you can now edit your CSS using any of the ModX tools. Additionally there are a few other perks:

  • 如果您像我一样,文件名很有用,但通常描述性不足.您可以根据自己的喜好命名!无论如何,它的别名仍然很重要.

  • If you're like me, file names are useful, but often not descriptive enough. You can name them whatever you like! Its the alias that is important anyway.

基于资源描述的便捷工具提示.

Handy tool-tips based on the Description of the resource.

您还可以将资源摘要用于其他用途.我在此处放置了重要的文件注释,以使CSS较小.

You may also utilize the Summary of the resource for other things. I place the important file comments in here, so that my CSS is smaller.

模板变量!在以前的ModX版本中,您的CSS没有模板.

Template Variables! In previous versions of ModX, you couldn't have a Template for your CSS.

大块和片段,如果您愿意的话.您必须将它们写为纯文本而不是HTML,但是如果您富有创造力,它仍然很有用.

Chunks and Snippets, if you so desire. You have to write them as plain text, rather than HTML, but it's still useful if you are creative.

您现在可以在所有上下文之间共享CSS.这是由于@import语句的性质所致.

Your CSS is now shared between all of your Contexts if you like. This is due to the nature of the @import statement.

您可以从任何计算机上编辑CSS.您甚至可以设置前端进行编辑.

You can edit your CSS from any computer. You may even set up your front-end for the editing.

总是需要权衡取舍,而采用这种技术并没有什么不同.很大程度上取决于您为网站设置的方式.

There's always trade-offs, and with this technique it is no different. A lot depends on how you have things set up for your site.

  • 您的保存和编辑取决于您的服务器性能.

  • Your saving and editing is based on your server performance.

您的URL请求将更多地基于您的ModX性能.对于某些人来说,添加这些额外的资源可能会使速度变慢.通常,它不足以担心,但值得一提.

Your URL requests will be based even more on your ModX performance. For some, adding these extra resources could slow things down. Often, its not enough to worry about, but its worth mentioning.

它现在由数据库管理,因此它受数据库安全性的影响.这可能是好事也可能是坏事.即使它很好,也可能需要您进行额外的设置.

It's now managed by the database, so its subject to database security. This can be good or bad. Even it is good, it probably will require extra set up from you.

如果编程不正确,您的模板,代码段和插件可能会破坏CSS.这是您真的要小心的事情.

Your Templates, Snippets and Plugins can break your CSS, if programmed incorrectly. This is something you really want to be careful with.

每个CSS请求都被ModX视为一个单独的请求.模板变量和插件不适用于您正在查看的网页.它们适用于CSS内容.

Each CSS request is treated as a separate request by ModX. The Template Variables and plugins do not apply to the web page you are viewing. They apply to the CSS content.

整个过程大约需要15分钟.最终,如果它对您不起作用,则还原甚至更快(只是在您确定之前不要删除原始文件).添加的功能对我来说是值得的.

The whole process takes about 15 minutes. And ultimately, it's even faster to revert back if it doesn't work for you (just don't delete the raw files until you are sure). The added functionality is worth it to me.

这篇关于我可以将CSS作为ModX资源进行管理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆