【问题标题】:Smarty Relative include pathSmarty 相对包含路径
【发布时间】:2010-09-23 17:03:55
【问题描述】:

文件结构如下:

index.php

settings/
|-manage_account.php

templates/viriditio-v2/
|-index.tpl

templates/virditio-v2/css
|-style.css

localhost/~braden/virditio/index.php 显示模板,如预期的那样显示 index.tpl,样式表路径正确显示:

<link rel="stylesheet" href="templates/virditio-v2/css/style.css" type="text/css"/>

但是localhost/~braden/virditio/settings/manage_account.php显示的路径相同,就是相对路径(应该是../才算完整)。

什么是使它相对于模板的简单方法?还是绝对的根?是否有包含 css 文件并使它们不相关的 Smarty 函数?

目前我的设置是这样的:

配置: template_url = "templates/virditio-v2/"

和.tpl: <link rel="stylesheet" href="{#template_url#}css/reset.css" type="text/css"/>

编辑

它并不漂亮,但我能够用它来完成它

{assign var='config_url' value=#template_url#}
{assign var='template_url' value=http://`$smarty.server.SERVER_NAME`$config_url}

还有更好的解决方案吗?

【问题讨论】:

    标签: php css smarty


    【解决方案1】:

    为什么不访问 CSS 之类的

    /templates/virditio-v2/css/style.css
    

    有绝对路径?

    如果它与子目录中的不同托管环境有关,请考虑使用配置选项来设置基本目录并将其作为变量附加到 smarty 模板中的路径。

    【讨论】:

      【解决方案2】:

      如果我理解正确,问题是无论页面来自文件夹树中的哪个位置,都需要将 CSS 文件链接到网页。这可以写成:

      <link rel="stylesheet" href="/~braden/virditio/templates/virditio-v2/css/style.css" type="text/css"/>
      

      这将使它成为从服务器根目录开始的固定路径。

      【讨论】:

      • 对,但是我正在制作一个需要可扩展并在多个托管环境中运行的系统。这就是我尝试动态创建它的原因...
      猜你喜欢
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多