Prestashop root directory

只谈情不闲聊 提交于 2019-12-08 02:14:56

问题


I am working with prestashop and in the theme I have added my own directory with a stylesheet inside it

I have then linked the stylesheet in header.tpl eg

<link rel="stylesheet" type="text/css" href="/directory/style.css" />

however If i install prestashop in a subdirectory eg

www.website.com/prestashop/ then the style is not showing because it thinks the root of the site is www.website.com. is there a pretsashop string I can use to echo the directory prestashop is installed in?

eg something like

$ps_dir or $ps_uri ???

So I can do something like this

<link rel="stylesheet" type="text/css" href="{$ps_dir}/directory/style.css" />

Cheers


回答1:


Assuming you're using PS 1.4 onwards, then you should really always enqueue additional stylesheets, although to do that you would need to either add a simple override to the FrontController class or create a theme-specific module. The advantage of this is that Prestashop will include your CSS (or javascript) into it's minimisation and CDN code, which can speed up your site considerably.

Is there any reason why you need to have a separate css file, and can't name the css you need for your theme global.css? Using the global.css file means that it will get included and minimised automatically.

If you perhaps need to add css conditionally (which is where you will have to hard-code it into the theme) or refer to other theme resources then you can also use the following variables:

{$css_dir} The /css directory in your theme
{$js_dir}  The /js directory in yout theme
{$img_dir} /img directory in your theme
{$tpl_dir} Your theme's top-level directory 



回答2:


These could be some usefuls variables to be used

(Take a look at PS_root/classes/controller/FrontConrtoller.php - line 310 in PrestaShop v 1.5.2)

 $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__,
        '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_,
        'modules_dir' => _MODULE_DIR_,
        'mail_dir' => _MAIL_DIR_,
        'lang_iso' => $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(),
        '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'),
        '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') || !(bool)Group::getCurrent()->show_prices,
        'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE'),
        'request' => $link->getPaginationLink(false, false, false, true)
    ));

I needed for a root absolute variable of my PrestaShop site for files inclusion so i have had to define a new one:

in PS_root/override/classes/controller/FrontConrtoller.php

class FrontController extends FrontControllerCore{
    $this->context->smarty->assign(array(
        'root_dir' => _PS_ROOT_DIR_
    ));
}



回答3:


you can use

<a href="{$base_dir}/directory/style.css">


来源:https://stackoverflow.com/questions/10428347/prestashop-root-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!