I am using Gantry 5 template and I want to add php code in the header. I set some variables using php and access them in the script tag. For example
<?php
$id = $user->id;
$name = $user->username;
?>
<script>
var id = '<?php echo $id; ?>';
var name = '<?php echo $name; ?>';
</script>
I want to add the above code in head of Gantry 5 template. In we just add the code in index.php but this mechanism is different in Gantry 5. How this code can be added?
Related
Magento version 2.3.2 show hide editor not working inside whole admin. When i try to add/update any product or pages and click on show/hide editor button editor does not show and inside console.log it show 404 not found mysite.com/static/adminhtml/Magento/backend/en_US/tinymce.js.
I have tried all related commands but not found where it is calling tinymce.js. In magento 2.3 correct path is static/adminhtml/Magento/backend/en_US/tiny_mce_4/tinymce.min.js
But i have no idea where i need to change this path. Inside require.js have no clue to find out real path.
Any one can help me.
I have tried all related commands
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
I have fixed issue by modify in lib/web/tiny_mce/tiny_mce_src.js
1-Find code near line 10833
tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
if (!/[\/\\]$/.test(tinymce.documentBaseURL))
tinymce.documentBaseURL += '/';
Replace with
tinymce.documentBaseURL = ADMIN_BASE_URL+"/tiny_mce";
tinymce.baseURL = ADMIN_BASE_URL+"/tiny_mce";
if(IS_MINIFY == 1) tinymce.suffix = '.min'; else tinymce.suffix = '';
2- Find code near line 11391
sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
Replace with
sl.add(tinymce.baseURL + '/langs/' + s.language + tinymce.suffix + '.js');
3- Find code near line 10758
tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
Replace with
tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + tinymce.suffix + '.js');
Change code in bellow file or override in admin theme:
vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml
4- Find code:
<script>
var BASE_URL = '<?php /* #escapeNotVerified */ echo $block->getUrl('*') ?>';
var FORM_KEY = '<?php /* #escapeNotVerified */ echo $block->getFormKey() ?>';
var require = {
"baseUrl": "<?php /* #escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
};
</script>
`
Replace code with:
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');
$isMinify = $scopeConfig->getValue('dev/js/minify_files', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
?>
<script>
var BASE_URL = '<?php /* #escapeNotVerified */ echo $block->getUrl('*') ?>';
var FORM_KEY = '<?php /* #escapeNotVerified */ echo $block->getFormKey() ?>';
var ADMIN_BASE_URL = '<?php /* #escapeNotVerified */ echo $block->getViewFileUrl('/') ?>';
var IS_MINIFY = '<?php /* #escapeNotVerified */ echo $isMinify ?>';
var require = {
"baseUrl": "<?php /* #escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
};
</script>
5- Run commands
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
We're having some issues with Magento 2 where we're unable to output the order values in our checkout code. Here's our code:
<!---- Onefeed Tracking Code ---->
<?php
//-------------------------------------------
// GET MAGENTO ORDER VALUES FOR TRACKING CODE
//-------------------------------------------
$orderId = $block->escapeHtml($block->getOrderId());
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
$total = $order->getGrandTotal();
?>
<script type="text/javascript" language="javascript">
var of_ssid = 'xxxx';
var cs = '<?php echo $total ?>';
var oi = '<?php echo $orderId; ?>';
var it = 1;
</script>
<script type="text/javascript" language="javascript" src="https://tracking.onefeed.co.uk/t.js"></script>
<noscript>
<img border="0" src="https://tracking.onefeed.co.uk/ProcessProductCheckout.ashx?of_ssid=xxxx&cs=<?php echo $total ?>&it=1&oi=<?php echo $orderId; ?>" />
</noscript>
<!---- End Onefeed Tracking Code ---->
Any ideas how we can output the data without having to create a module in Magento 2?
This part of your code is definately working (just checked):
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);
$total = $order->getGrandTotal();
?>
...
<?php echo $total ?>
Since I don't know which Block functions you are relying on it's impossible to say for sure, but I'm guessing $orderId = $block->escapeHtml($block->getOrderId()); does not return a valid order id.
I'm not sure if you should use objectManager though. There is quite a discussion about when and how to use it on the stackexchange:
https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly
When 404 Page Not Found error occurs application/errors/error_404.php template is used in CodeIgniter. I need to access the base_url() function inside that template. Any suggestion on how base_url() or site_url() functions can be accessed inside error_404.php will be really helpful.
you might want to use this simple trick. Just change the code below:
<?php echo base_url() ?>
to:
<?php echo config_item(‘base_url’); ?>
credit for https://www.petanikode.com/codeigniter-base-url-404/
this work for my case
Try following in application/errors/error_404.php
$CI =& get_instance();
if( ! isset($CI))
{
$CI = new CI_Controller();
}
$CI->load->helper('url');
echo $CI->base_url();
Try this in top of your 404 page:
$CI =& get_instance();
if( ! isset($CI))
{
$CI = new CI_Controller();
}
$CI->load->helper('url');
echo base_url();
// below here base_url(), site_url() will work
Work for all pages under views/errors/html folder
you can directly use these functions, because these are global functions.
eg: you are in 404 page template
<html>
<head>
<title> 404 Error </title>
</head>
<body>
<?php echo base_url('/your path'); ?>
<?php echo site_url('/your path'); ?>
</body>
</html>
Edited
goto your application/config/autoload.php file and add url in autoload array
$autoload['helper'] = array('url', 'form');
after this you can directly use <?php echo base_url('/your path'); ?> everywhere
Edit your /application/config/routes.php
$route['404_override'] = 'your_controller/error';
Add function into your_controller.php
function error(){
show_404();
}
You are ready to go.
refer https://stackoverflow.com/a/48033542/7840849
or do followings
$autoload['helper'] = array('url'); in application\config\autoload.php file
Then simply use echo config_item('base_url'); instead of echo base_url(); in codeigniter default error pages
$autoload['helper'] = array('url'); in application\config\autoload.php file
Then simply use echo config_item('base_url'); instead of echo base_url(); in codeigniter default error pages
this work for my case, try this method
Change the function base_url() to config_item('base_url')
<?php echo config_item('base_url'); ?>
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();
Check if you have something configured inside the config file /application/config/config.php e.g.
$config['base_url'] = 'http://example.com/';
**Then**
u can use like this..
<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
I have the following code for joomla 2.5 ....
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$id = 474;
$link = JRoute::_($menu->getItem($id)->link);
?>
<script>
$(document).ready(function(){
var $link = $('<a>',{
class: 'all-news-link',
href: <?php echo json_encode( $link ); ?>
});
$('#custom-module .moduletable:nth-child(2) h3').append($link);
});
</script>
But it is not getting menu id 474 but 468 that is home page id. My SEF is also not turned on.
You should be able to just do this:
$link = 'index.php?Itemid=474';
Assuming that the location that you print it on the page is picked up by the system plugin that routes output all will be well.
If that is actually what makes it to the page, then you would want to route it manually:
$link = JRoute::_('index.php?Itemid=474');
The router will handle getting the link for you.
I am in need to get the Json Config by product id or sku in the product listing page for a particular category.
I can see that getJsonConfig is decalred in Product options block where only one particular product is showing thats why it can show Json Config without saying the product id. But I am in product list page.
Is there any way to get it like below?
$this->getJsonConfig($productId);
$this->getJsonConfig()
The method is part of
class Mage_Catalog_Block_Product_View
and it calls
/* #var $product Mage_Catalog_Model_Product */
$product = $this->getProduct();
public function getProduct()
{
if (!Mage::registry('product') && $this->getProductId()) {
$product = Mage::getModel('catalog/product')->load($this->getProductId());
Mage::register('product', $product);
}
return Mage::registry('product');
}
So to use it ( in any other page ) you have to set product in the block instance as below :
Mage::register('product', $_product); // add the product object in the registry
$block = Mage::getBlockSingleton('Mage_Catalog_Block_Product_View'); // Instantiate the product view block
echo $block->getJsonConfig();
I found a simple solution for configurable product view page.
Hope that will help.
if ($_product->isConfigurable())
{ $block1 = Mage::app()->getLayout()->createBlock('catalog/product_view');
$block1->setProduct($_product);
$configPrice = $block1->getJsonConfig(); //var_dump( $config = $block->getJsonConfig`enter code here`() );
$block2 = Mage::app()->getLayout()->createBlock('catalog/product_view_type_configurable');
$block2->setProduct($_product);
$config = $block2->getJsonConfig();
}
<?php if ($_product->isConfigurable()): ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $configPrice ?>);
</script>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $config ?>);
</script>
<?php endif; ?>