Magento - 从管理文件链接到前端皮肤 js 文件

发布于 2024-10-07 11:03:16 字数 367 浏览 2 评论 0原文

我已经在我的前端皮肤文件中使用 jQuery。我现在在管理 phtml 文件中添加了一些额外的功能,这也需要使用 jQuery。我不想包含它两次,但是假设我不知道前端正在使用什么主题包名称(因为显然这可以改变,所以我不知道如何动态链接到现有的 jQuery 文件)不希望它被硬编码)?

例如,我尝试了这个,但它给了我管理主题包名称,而不是前端包:

<?php
    // Get the package name
    $configData = Mage::getStoreConfig('design');
    $package = $configData['package']['name'];
?>

有人吗?

I'm already using jQuery in my frontend skin files. I've now added some extra functionality in an admin phtml file, that also needs to use jQuery. I don't want to have to include it twice, but how can I link to the existing jQuery file dynamically, assuming I don't know what theme package name is being used on the frontend (because obviously that can change, so I don't want it hardcoded)?

For example, I tried this, but it gives me the admin theme package name, not the frontend package:

<?php
    // Get the package name
    $configData = Mage::getStoreConfig('design');
    $package = $configData['package']['name'];
?>

Anyone?

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

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

发布评论

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

评论(2

静赏你的温柔 2024-10-14 11:03:16

好的,这似乎有效。我可以直接访问数据库,在 core_config_data 表中查找“design/package/name”,然后使用以下命令构建 js 文件的 url:

<?php // Get the current theme being used, so we can build the url link to our jQuery file
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tablename = Mage::getSingleton('core/resource')->getTableName('core_config_data');
$results = $connection->fetchAll("SELECT * FROM $tablename WHERE path='design/package/name';");
foreach($results as $row) { $theme = $row['value']; };
?>
<script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/'.$theme; ?>/default/js/jquery.min.js"></script>

OK, this seems to be working. I can access the db directly, look for the "design/package/name" in the core_config_data table and then build the url to the js file using that:

<?php // Get the current theme being used, so we can build the url link to our jQuery file
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$tablename = Mage::getSingleton('core/resource')->getTableName('core_config_data');
$results = $connection->fetchAll("SELECT * FROM $tablename WHERE path='design/package/name';");
foreach($results as $row) { $theme = $row['value']; };
?>
<script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN).'frontend/'.$theme; ?>/default/js/jquery.min.js"></script>
始终不够爱げ你 2024-10-14 11:03:16

对我来说帮助将 $storeId 设置为 1 而不是 0

$package = Mage::getStoreConfig('design/package/name', 1);
$theme   = Mage::getStoreConfig('design/theme/default', 1);

for me helped to set $storeId as 1 not 0

$package = Mage::getStoreConfig('design/package/name', 1);
$theme   = Mage::getStoreConfig('design/theme/default', 1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文