Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在Smarty 2模板中包含或导入(@import)样式表_Html_Css_Smarty_Stylesheet_Smarty2 - Fatal编程技术网

Html 在Smarty 2模板中包含或导入(@import)样式表

Html 在Smarty 2模板中包含或导入(@import)样式表,html,css,smarty,stylesheet,smarty2,Html,Css,Smarty,Stylesheet,Smarty2,我有一个Smarty 2模板,我希望使用CSSimport,甚至只是一个常规的标记来包含CSS文件,而不是使用传统的{literal}标记与内联CSS 这在Smarty 2中可能吗 CSS文件与Smarty模板位于同一目录中,因此我只想从同一目录中获取它—但这不起作用 <link href="{$smarty.server.PHP_SELF}thumbnails.css" rel="stylesheet" type="text/css" /> CSS@import功能也不可用。

我有一个Smarty 2模板,我希望使用CSS
import
,甚至只是一个常规的
标记来包含CSS文件,而不是使用传统的
{literal}
标记与内联CSS

这在Smarty 2中可能吗

CSS文件与Smarty模板位于同一目录中,因此我只想从同一目录中获取它—但这不起作用

<link href="{$smarty.server.PHP_SELF}thumbnails.css" rel="stylesheet" type="text/css" />


CSS
@import
功能也不可用。

您可以尝试以下操作:

使用{php}标记:

<style>
{php}include('/filesystem/path/to/thumbnails.css');{/php}
</style>
然后用以下词语来称呼它:

<style>
{include_file file='/filesystem/path/to/thumbnails.css'}
</style>
然后包括:

<style>
{include file = "thubnails.css"}
</style>

{include file=“thubnails.css”}
如果您不介意编辑css文件,请使用此示例


请记住,上述所有情况显然都将所有文件作为内联样式表包含在内,这不是一个好的做法。更好的方法是将css文件放在可以通过web访问的地方(也就是说,您可以使用
http://yoursite.example.com/path/to/css/thumbnails.css
)然后像现在一样硬链接到它

$smarty.server.PHP\u SELF返回执行模板的当前文件的名称和路径,即htt…/mypage.PHP,如果在呈现remplate后查看源代码,您将看到css未加载的原因

相反,在php文件中声明一个具有所需路径的变量,并将其传递给smarty(在示例中,$css\u path):



令人沮丧的是,我必须将
{literal}
标签包裹在
缩略图中的所有CSS上。CSS
才能让它正常工作-在IDE中打开时,它看起来不太好;将它们放在{include}之前和之后,或者放在css文件的开头和结尾(我已经更新了上面的示例)Hmmm…这是不对的,因为
{literal}
标记将意味着Smarty按字面意思处理内容,即不会解析它们。因此,在本例中,它将输出不正确的
{include file=“thumbnails.css”}
。尝试更新的version@crmpicco:我已经用我这次实际尝试过的方法更新了我的答案!
/*{literal}*/
body{background-color:red!important}
/*{/literal}*/
<style>
{include file = "thubnails.css"}
</style>
<link href="{$css_path}thumbnails.css" rel="stylesheet" type="text/css" />