如何获取 prestashop 的 .tpl 文件中当前主题的 url

发布于 2024-12-05 00:29:28 字数 332 浏览 0 评论 0原文

我需要获取位于 www.mysite.com/themes/mytheme/img/image.png 的图像路径

========================== =========================

我在这里找到了答案:http://prestalab.ru/wiki/peremennye-v-shablonax

我的主题中图像的路径为:{$tpl_dir}img/myimage.png

I need to get path of image which is located in www.mysite.com/themes/mytheme/img/image.png

=================================================

I've found the answer here: http://prestalab.ru/wiki/peremennye-v-shablonax.

The path to image in my theme will be: {$tpl_dir}img/myimage.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冷夜 2024-12-12 00:29:28

$tpl_uri 将返回当前主题相对于网络根目录的路径。

以下是 PrestaShop 提供的其他一些全局变量,可能会有所帮助:

$img_ps_dir       // the PrestaShop image directory
$img_cat_dir      // current category's images directory
$img_lang_dir     // current language's images directory
$img_prod_dir     // current product's images directory
$img_manu_dir     // current manufacturer's images directory
$img_sup_dir      // current supplier's images directory
$img_ship_dir     // current carrier's (shipping) images directory
$img_dir          // current theme’s images directory
$css_dir          // current theme’s CSS directory
$js_dir           // current theme’s JavaScript directory
$tpl_dir          // current theme’s directory (physical path on machine)
$tpl_uri          // current theme's directory (web-root relative path)
$modules_dir      // modules directory
$mail_dir         // mail templates directory
$pic_dir          // pictures upload directory

$tpl_uri will return the current theme's path relative to the web root.

Here are some other global variables PrestaShop makes available which may be helpful:

$img_ps_dir       // the PrestaShop image directory
$img_cat_dir      // current category's images directory
$img_lang_dir     // current language's images directory
$img_prod_dir     // current product's images directory
$img_manu_dir     // current manufacturer's images directory
$img_sup_dir      // current supplier's images directory
$img_ship_dir     // current carrier's (shipping) images directory
$img_dir          // current theme’s images directory
$css_dir          // current theme’s CSS directory
$js_dir           // current theme’s JavaScript directory
$tpl_dir          // current theme’s directory (physical path on machine)
$tpl_uri          // current theme's directory (web-root relative path)
$modules_dir      // modules directory
$mail_dir         // mail templates directory
$pic_dir          // pictures upload directory
清引 2024-12-12 00:29:28

有时查看代码就足够了,看看分配的所有基本变量:

// FrontController Class
$this->context->smarty->assign(array(
        // Usefull for layout.tpl
        'mobile_device' => $this->context->getMobileDevice(),
        'link' => $link,
        'cart' => $cart,
        'currency' => $currency,
        'cookie' => $this->context->cookie,
        'page_name' => $page_name,
        'hide_left_column' => !$this->display_column_left,
        'hide_right_column' => !$this->display_column_right,
        'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
        'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,
        'force_ssl' => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'),
        'content_dir' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__,
        'base_uri' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''),
        'tpl_dir' => _PS_THEME_DIR_,
        'tpl_uri' => _THEME_DIR_,
        'modules_dir' => _MODULE_DIR_,
        'mail_dir' => _MAIL_DIR_,
        'lang_iso' => $this->context->language->iso_code,
        'lang_id' => (int)$this->context->language->id,
        'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code,
        'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))),
        'cart_qties' => (int)$cart->nbProducts(),
        'currencies' => Currency::getCurrencies(),
        'languages' => $languages,
        'meta_language' => implode(',', $meta_language),
        'priceDisplay' => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer),
        'is_logged' => (bool)$this->context->customer->isLogged(),
        'is_guest' => (bool)$this->context->customer->isGuest(),
        'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
        'shop_name' => Configuration::get('PS_SHOP_NAME'),
        'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
        'use_taxes' => (int)Configuration::get('PS_TAX'),
        'show_taxes' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),
        'display_tax_label' => (bool)$display_tax_label,
        'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
        'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
        'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices),
        'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE'),
        'request' => $link->getPaginationLink(false, false, false, true),
        'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'),
        'quick_view' => (bool)Configuration::get('PS_QUICK_VIEW'),
        'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
        'compared_products' => is_array($compared_products) ? $compared_products : array(),
        'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
        'currencyRate' => (float)$currency->getConversationRate(),
        'currencySign' => $currency->sign,
        'currencyFormat' => $currency->format,
        'currencyBlank' => $currency->blank,
    ));

Sometimes its enought to look at code, to see all basic variables assigned:

// FrontController Class
$this->context->smarty->assign(array(
        // Usefull for layout.tpl
        'mobile_device' => $this->context->getMobileDevice(),
        'link' => $link,
        'cart' => $cart,
        'currency' => $currency,
        'cookie' => $this->context->cookie,
        'page_name' => $page_name,
        'hide_left_column' => !$this->display_column_left,
        'hide_right_column' => !$this->display_column_right,
        'base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
        'base_dir_ssl' => $protocol_link.Tools::getShopDomainSsl().__PS_BASE_URI__,
        'force_ssl' => Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'),
        'content_dir' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__,
        'base_uri' => $protocol_content.Tools::getHttpHost().__PS_BASE_URI__.(!Configuration::get('PS_REWRITING_SETTINGS') ? 'index.php' : ''),
        'tpl_dir' => _PS_THEME_DIR_,
        'tpl_uri' => _THEME_DIR_,
        'modules_dir' => _MODULE_DIR_,
        'mail_dir' => _MAIL_DIR_,
        'lang_iso' => $this->context->language->iso_code,
        'lang_id' => (int)$this->context->language->id,
        'language_code' => $this->context->language->language_code ? $this->context->language->language_code : $this->context->language->iso_code,
        'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace(array('\'', '\\'), '', urldecode($_SERVER['REQUEST_URI']))),
        'cart_qties' => (int)$cart->nbProducts(),
        'currencies' => Currency::getCurrencies(),
        'languages' => $languages,
        'meta_language' => implode(',', $meta_language),
        'priceDisplay' => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer),
        'is_logged' => (bool)$this->context->customer->isLogged(),
        'is_guest' => (bool)$this->context->customer->isGuest(),
        'add_prod_display' => (int)Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
        'shop_name' => Configuration::get('PS_SHOP_NAME'),
        'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
        'use_taxes' => (int)Configuration::get('PS_TAX'),
        'show_taxes' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')),
        'display_tax_label' => (bool)$display_tax_label,
        'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
        'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
        'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') || (Group::isFeatureActive() && !(bool)Group::getCurrent()->show_prices),
        'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE'),
        'request' => $link->getPaginationLink(false, false, false, true),
        'PS_STOCK_MANAGEMENT' => Configuration::get('PS_STOCK_MANAGEMENT'),
        'quick_view' => (bool)Configuration::get('PS_QUICK_VIEW'),
        'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
        'compared_products' => is_array($compared_products) ? $compared_products : array(),
        'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
        'currencyRate' => (float)$currency->getConversationRate(),
        'currencySign' => $currency->sign,
        'currencyFormat' => $currency->format,
        'currencyBlank' => $currency->blank,
    ));
北方的韩爷 2024-12-12 00:29:28

mytheme img 文件夹有一个全局 smarty 变量 - img_dir

查看 Prestashop 中的所有 Smarty 全局变量:
http://saidul.songzog.com /my-blog/details/848/smarty-global-variables-in-prestashop.html

There is a global smarty variable for mytheme img folder which is - img_dir

See all Smarty Global variables in Prestashop:
http://saidul.songzog.com/my-blog/details/848/smarty-global-variables-in-prestashop.html

栩栩如生 2024-12-12 00:29:28

在 PS 1.6 上,我发现我需要添加一个 smarty 变量来获取我的主题的 uri。在
类/控制器/FrontController.php
在设置 tpl_dir 的第 333 行,我在下面添加了这一行:

'tpl_uri' => _THEME_DIR_,

它返回主题的路径。

On PS 1.6 I found that I needed to add a smarty variable to get my theme's uri. In
classes/controller/FrontController.php
on about line 333 where tpl_dir is set, I added this line below:

'tpl_uri' => _THEME_DIR_,

which returns the path the theme.

喜爱纠缠 2024-12-12 00:29:28

对于 PS1.7,您可以使用

{$urls.img_url}

获取当前主题的图像目录的路径。

For PS1.7, you can use

{$urls.img_url}

to get a path of the image directory of your current theme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文