After compressing the JS file in Drupal I got a randomly JS file name.
My question how I can get this file name to add it to my javascript?
Drupal code: import and compress
<?php drupal_add_js(drupal_get_path('theme', 'mytheme') . 'mybigfile.js'); ?>
Random file name Result:
js_2KQpJNjjupC1Beoweoqpok2JCXhe0sJ6YBllaRDUXYQ.js
Trying to Call the mybigfile.js file:
<script>
telInput.intlTelInput({
validationScript: "mybigfile.js"
});
</script>
As far as I know, you can not get the name of the concatenated JavaScript file generated by Drupal using PHP.
Your best option would be to avoid your JavaScript file mybigfile.js from being concatenated and compressed. Then you can apply your validation script by calling the file name.
You will have to set the preprocess property to false inside drupal_add_js $options array, to prevent the file from being aggregated.
drupal_add_js(drupal_get_path('theme', 'mytheme') . '/mybigfile.js', array(
'type' => 'file',
'preprocess'=> false,
));
Update
If you want to compress a single JavaScript file, you have the option to use AdvAgg API.
Unfortunately, I can't find any documentation for how to do that. But you start with the following:
download and install advagg and enable the submodule advagg_js_compress.
inside the advagg_js_compress submodule folder, find the file advagg_js_compress.advagg.inc and open in your text editor. Here you can find a few helper functions that will help you compressing your JavaScript file.
Related
I am unable to add javascript files to my first Shopware5 theme. I tried the following method given in one of online articles.
https://developers.shopware.com/designers-guide/theme-startup-guide/
I added my js files into the array on Theme.php file and upload javascript files to the ‘frontend/_public/src/js’
/** #var array Defines the files which should be compiled by the
javascript compressor */
protected $javascript = array(
'src/js/jquery.my-plugin.js'
);
However the above array was not avilable on my Theme.php file but I added my js files into the array and tried loading it on my theme. I cleared all my caches when I checked the site.
You have to clear all caches and also do a re-compile of the theme. Have in mind that you have to place the js into frontend/_public.
The full path of your js-files should be themes/YourTheme/frontend/_public/src/js/jquery.my-plugin.js.
i want to convert PDF uploaded by user to HTML file and shown on browser.
so for that is there any simple solution in php , jquery or js.
Thanks in advance.
the supporting software is available, you can use that one:
1. download and unpack the .exe file to a folder: PDFtoHTML
2. Create a .php file, & put this code (assuming, that pdftohtml.exe is inside that folder, and the source test.pdf as well)
<?php
$source_pdf="test.pdf";
$output_folder="MyFolder";
if (!file_exists($output_folder)) { mkdir($output_folder, 0777, true);}
$a= passthru("pdftohtml $source_pdf $output_folder/new_file_name",$b);
var_dump($a);
?>
3. enter MyFolder, and you'll see the converted files
Javascript file's order is not correct in Drupal. On other pages other than print page the order of script files are correct. The files are drupal.js and google_analytics_reports.js
Since the order is not correct it is causing error
"ReferenceError: Drupal is not defined"
Please help me to change the order of the files in Print pages(When we try to take a print out of the page, we will get this print page).
Are you sure that this is a problem of the js files order and not
something else?
Are the same js files loaded on print and normal pages?
What files are inside the /templates folder of your theme (or
generally files with tpl.php extension under your theme folder)?
If you just need a template for the printing mode install the print module and copy the print.tpl.php file into your theme templates folder. Then edit it as you prefer.
I have a (javascript) script in my CakePHP plugin which creates an img tag in the current viewed document. The problem is, that every try to provide a valid image source have failed until now. The plugin resides in the plugin directory of the CakePHP library (not the CakePHP app), as we use it for several independent apps which have a lot of commons.
The images are located in /cake/plugins/Corporate/webroot/img.
The (javascript) script is located in /cake/plugins/Corporate/webroot/js.
The relative path from script to image does not work (../img/image.png). The CakePHP routing path (/Corporate/img/image.png) does not work either, independent if I prepend the plugin name or not.
Use the right path
The right path to get to a webroot asset in the PluginName plugin is of the form:
/plugin_name/path
I.e.:
Filepath: App/Plugin/Corporate/webroot/img/image.png
Url: /corporate/img/image.png
In early versions of CakePHP asset dispatching was automatic, while in 2.2+ asset dispatching must be explicitly enabled.
The normal way to deal with plugin assets is to not use the asset dispatch filter and to copy (or symlink) the files to the application webroot in the same path as corresponds to the url i.e.:
cd App
cp -R Plugin/Corporate/webroot webroot/corporate
This means that the url requested directly maps to a file in the application webroot folder - there is no php logic invoked in serving these files which amongst other benefits makes serving such assets significantly faster.
Dealing with paths in javascript
If an application is always, always installed as the root of the domain (http://example.com) there is absolutely no complexity - just refer to the relative path to the image:
var imagePath = '/corporate/img/image.png';
If however the root of the application is variable (http://example.com/, http://exmaple.com/sub/folder/, http://localhost/someproject/) - it's necessary to tell the javascript what to consider the root of the application. for example put the following in the layout file:
<head>
...
<script>ROOT = '<?= $this->Html->url('/'); ?>';</script>
</head>
<body>
<?= $this->fetch('content'); ?>
...
</body>
In this way, javascript can refer to the global ROOT anywhere to know what the root url is, like so:
var imagePath = ROOT . 'corporate/img/image.png';
This makes it possible to use the same javascript irrespective of how the application is installed.
you can use this code
<?php echo $this->Html->image("recipes/6.jpg", array( "alt" => "Brownies", 'url' => array('controller' => 'recipes', 'action' => 'view', 6))); ?>
Altough, the question is very old but still I want to answer this for anybody else looking for it
You could use
<?php
echo $this->Html->image( $this->Html->url('/', true).'{plugin_name}/{folder_name}/{asset_name}');
?>
For example,
<?php
echo $this->Html->image( $this->Html->url('/', true).'Corporate/img/image.png');
?>
Note here that plugin_name and asset_name are case sensitive.
I am trying to add an external javascript file to Codeigniter application.
I have placed my external js file in the "projectname/js/" folder.
Below is the script tag src in my view page.
src="http://localhost/needpcbcodeigniter/js/registration.js">
But I am getting a "Not found" error for the js file.
Most probably this is because the apache mod_rewrite is dealing with the js folder as a codeigniter controller name (as if you're calling http://localhost/projectname/index.php/js/registration.js)
Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. Check it here
You should add an external javascript file to codeigniter in assets folder.
You should check some following steps :-
1) first fix your project base_url which is set in application/config/config.php like-
$config['base_url'] = 'http://localhost/yourprojectname/'
2) create a folder(e.g: js) in assets folder(at root of folder) for save all javascript files(e.g : registration.js).
3) on final step where you want to use javascript file use code like this-
<script src="<?php echo base_url();?>/assets/js/registration.js"></script>