Dynamically embed inline-CSS to head using Prestashop module - prestashop-1.7

How can I dynamically embed an inline-CSS that was entered via the back office. There're only two register methods available for registering assets in Prestashop.
public function hookDisplayHeader()
{
$this->context->controller->registerJavascript('id', 'path/to/file.js');
$this->context->controller->registerStylesheet('id', 'path/to/file.css');
}
The registerStylesheet method has an option called inline, but that requires the content to be in an existing file first. While I have the CSS code stored in the configurations.
And trying to echo the content in hookDisplayHeader() results in it being printed above the <html> open tag.

Create a TPL file in the hooks directory of your module.
Then get the CSS code value from configurations in hookDisplayHeader() function and pass it to smarty:
$custom_css = `GET CUSTOM CSS FROM CONFIG`;
$this->smarty->assign('yourcustomcss', $custom_css);
return $this->display(__FILE__, 'dummy_file.tpl');
Then in the TPL file: dummy_file.tpl
{if isset($yourcustomcss)}
<style>{$yourcustomcss nofilter}</style>
{/if}
The TPL file is supposed to be in the following directory:
/yourmodule/views/templates/hook/dummy_file.tpl

Related

Date and Time picker in Ruby

I like to start a simple work in sinatra(small ruby framework). For this purpose i like to know how to use a date and time picker in ruby. I use a datepicker like below
$("#jobdate_from").datepicker(); $("#jobdate_to").datepicker();
I wrote this line in an erb file, if anyone know, at least have an idea about this, please share
Thank you
Your date picker is a HTML/CSS/JS thing.
Write the correct markup in your erb file, put your styleing in a corresponding CSS file and write your initialization in your js file.
To include it in your generated HTML you can set your public folder with the
set :public_folder, Proc.new { File.join(root, "static") }
command. (Has only to be done if it is not called public anyway). Be sure to create a stylesheet/javascript folder underneath.
If you have done this, you can access your js/css files from within your erb file as you would access a normal method because the view is evaluated in the same context as your method where you called it.

How to use SassDoc as parser for single file without generating full documentation files

Question relates to http://sassdoc.com package
I would like to parse each *.scss file in ./source folder, but instead of generating sassdoc folder i would like to create partial-html for each parsed file. For example:
parse: variables.scss and receive variables.html, without page header, sidebar - pure content, even without html and body tags.
My current code:
var gulp = require('gulp'),
sassdoc = require('sassdoc');
var paths = {
scss: [
'source/**/*.scss'
]
};
gulp.task('sassdoc', function () {
console.log("sassdoc task finished");
return gulp.src(paths.scss)
.pipe(sassdoc());
});
It's not possible with SassDoc' default theme. So you'd need to build your own theme to acheive this.
http://sassdoc.com/using-your-own-theme
Each item is given a file key in resulting data, so I would leverage that and do some merging.
That could potentially end up in a sassdoc-extra custom filter.
http://sassdoc.com/extra-tools
EDIT:
Actually your question is quite misleanding, you want a variable.html file but with no html ...
If all that you want is the raw JSON data from SassDoc, without any kind of theme processing, then the parse method is what you're looking for.
But again, unless you call SassDoc on each file separately, you'll get all files together, meaning post data processing to split them, that's why a custom theme (even with no html output) is the way to go.

Extends class makes ajax call

I am very new to ExtJS 4 and I have a problem extending a class. I have these files:
UsersWindow.js
Ext.define('MyDesktop.UserModel', {
extend: 'Ext.data.Model',
/* ... */
}
Ext.define('MyDesktop.UsersWindow', {
/* ... */
}
DealersWindow.js
Ext.define('MyDesktop.DealerModel', {
extend: 'MyDesktop.UserModel',
/* ... */
}
Ext.define('MyDesktop.DealersWindow', {
extend: 'MyDesktop.UsersWindow',
/* ... */
}
When I run the application, everything works as expected, however, I have this ajax call:
/UserModel.js?_dc=1379135132790
that gives a 404, and then a error parsing the javascript. I want to understand why ExtJS making this call ? Does every class should be in there own file ? Can I configure ExtJS to no look for this file ?
Thank you for your help.
Yes, every class has to be in its own file for the Ext Loader to work properly. Beside, the name of the file should be the same as the class, and its path should match the namespace.
What happens here is that the extend: 'MyDesktop.UserModel' line prompts the Ext.Loader to load the UserModel class, that it expects to find in the UserModel.js file in the root path for the MyDesktop namespace, which seems to be configured as the root directory of the application...
You can configure root source directories for different namespaces with the paths property of the Loader, or the one of the Application.
If you want to prevent Ext from trying to load this file, you will have to disable the Loader, and then you will have to include all your source files as <script> tags in your HTML. I think this will also make it impossible to compile a production build of the application later.
Alternatively, you could put your definition of MyDesktop.UserModel above the definition of MyDesktop.DealerModel, either in the same file or a file before it in the script tags. Note that even this may not work, because the requires option in your classes definitions may change the order in which the class definition are actually executed. Then again, that will probably break the build process ultimately...
In short, you should not try to work again the framework's expectations. Especially when you consider that the 1:1 mapping between class names and the file system is standard practice in about every OO language out there...

codeigniter - use custom config value inside CI config file

I got custom.php (inside config folder) with code like below
$config['myurl'] = 'somesite.com';
I got config.php ( standard CI ), I want to set the base_url using the value from custom.php, like this
$config['base_url'] = $this->config->item('myurl');
Doing that I got the error
Using $this when not in object context in /Volumes/HD 2/work/vnl/app/config/config.php on line 18
Whats the right code for this purpose?
This is not going to work there. The $this that you would want to use there is a controller instance and that is not created yet when the standard application/config/config.php loads.
You can try to add a pre_system hook (that's loaded right before the config object) and include in some helper function that can be called and return the desired value in the application/config/config.php. The usual constants like APPPATH will be available then.
If you can make this config variable a constant that can work too (just put the define() inside application/config/constants.php). Since the config file is just a regular php source file, you can have conditionals here too if you must.
You can just work with the arrays.
In your custom config file
$config['myurl'] = 'myurl.com';
$config['base_url'] = &$config['myurl'];
This will change the default base_url once the custom config file is loaded, you can also just reset the base_url element in your custom config, however in my opinion it is not recommended to reset the base url in another config file as later in the project you could lose track of where it is set, why not set it (and maybe use conditions) in the main config file?

smarty template engine

I have an webpage written using php but now need to convert them to smarty template engine.
I am rookie to smarty template engine.I find it difficult of smarty.net document.Is there any book or site from where i can learn smarty.
I need a small snippet for insert function.
I think the smarty.net documentation is the very best point to start using Smarty Template Engine.
Most tutorials are based on the documentation I think.
For a very quick start you just have to require the Smarty base class:
// Require base class
require_once('Smarty.class.php');
// create new Smarty instance
$smarty = new Smarty();
// define Smarty directories
$smarty->template_dir = '/web/www.example.com/guestbook/templates/';
$smarty->compile_dir = '/web/www.example.com/guestbook/templates_c/';
$smarty->config_dir = '/web/www.example.com/guestbook/configs/';
$smarty->cache_dir = '/web/www.example.com/guestbook/cache/';
// define a template variable, which will be shown in your template
$smarty->assign('greeting', 'Hello World!');
// force your php script to show your template file
$smarty->display('template.html');
Thats everything you need in your PHP file.
In the default configuration of Smarty you can show your template variable greeting by using
My greeting message: {$greeting}
If you open your PHP File via a browser you will see: My greeting message: Hello World!
For further information you really should read the official Smarty documentation!

Resources