Dynamic load css with CakePHP on a Page - css

I am using CakePHP 2.0 and I want to load a concrete CSS style in a Page. (with no controller but using the Layout).
I know it can be done with scripts using:
$this->Html->script('photos', array('inline' => false));
And then on the Layout:
<?php echo $scripts_for_layout; ?>
But i have no idea if it exists or not something similar to $scripts_for_layout; for CSS style.
Do you know how can i do it?

If you can upgrade to 2.1 then you can use this:
// in your view
$this->Html->script('carousel', array('block' => 'scriptBottom'));
// in your layout
echo $this->fetch('scriptBottom');
http://book.cakephp.org/2.0/en/views.html#using-blocks-for-script-and-css-files
update:
In earlier versions you could do it like you do with scripts:
$this->Html->css('some.css', null, array('inline' => false));
And it will be placed to $scripts_for_layout.

Related

Drupal: Password textfield in everypage, how can I remove?

After migration, every page add password textfield at the end of every page.
What is this? How can I remove or troubleshoot?
Drupal 7.27 with apache 2.4 and php 7.0 (same problem with php 5.6.35).
Look there is a script loaded on these pages (just above the <form> itself) that creates the input tags and set the windows focus in it :
<script type="text/javascript">
var d = document;
d.write("<br><br><form method='post'><center><input type='password'...>...");
// ...
</script>
You want to remove this script.
Since there are several ways to include javascript with Drupal it may be difficult to spot the code responsible for that. Given the ugliness of the script itself, it could very well be harcoded in a theme template file (in this case, theme switching during migration would explain why your issue suddenly arose).
The chance is that ugly snippets like this is quite often hardcoded so you can make a search for a part of the js string (e.g. 'd.write("<br><br><form') in your project at the root of your site and/or in sites/all.
Lastly, find the guy that wrote this and beat him ;)
Your code is including a java script in every page which is creating input type password since it is included in every page that's why you are getting this field.
kindly check your requirement for same.
In drupal We can add JS in drupal by following method
1.)By drupal_add_js() function
drupal_add_js() is drupal api function to include js.
Example:
drupal_add_js('misc/collapse.js');
// add JS file
drupal_add_js('misc/collapse.js', 'file');
// For including inline javascript
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
//For including inline javascript and includ and includ it in footer
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 5,
));
//For including External JS
drupal_add_js('http://example.com/example.js', 'external');
//For passing php value to JS
drupal_add_js(array(
'myModule' => array(
'key' => 'value',
),
), 'setting');
Example:
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');
for more infomation visit https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7.x
2.)Adding by Form API
we can used '#attached' property of form api for including js
Example:
$form['#attached']['js'] = array(
drupal_get_path('module', 'ajax_example') . '/ajax_example.js',
);
3.)Adding JS in info file
We can including javascript in script file
Example:
name = My theme
description = Theme developed by me.
core = 7.x
engine = phptemplate
scripts[] = mytheme.js
4.)By preprocess function
if we want to conditionaly include JS we can include it in preprocess function
function mytheme_preprocess_page(&$vars, $hook) {
if (true) {
drupal_add_js(drupal_get_path('theme', 'mytheme') . '/mytheme.js');
$vars['scripts'] = drupal_get_js(); // necessary in D7?
}
}

Working with forms in drupal 8

I am facing problem with "#markup" in form API.
In Drupal 7 we can use "#markup" form element which look like this:
<?php
$form['test'] = array(
'#type' => 'markup',
'#markup' => '<div><script src="http://localhost/drupal7/sites/all/libraries/test.js"></script></div>',
);
?>
//Here is my custom test.js
(function($) {
Drupal.behaviors.test = {
attach: function(context, settings) {
console.log('testttt');
document.write('*Hello, there!*');
}
};
})(jQuery);
and above code will print "Hello, there!" when form will be render.
Now in Drupal 8 I am using below code but it prints nothing.
<?php
$form['test'] = array(
'#markup' => '<div><script src="http://localhost/project8/sites/all/libraries/test.js"></script></div>',
);
?>
So how can implement this functionality in Drupal 8, which is already working in Drupal 7 .
Under script tag it can be local script or external script..
Please help...
Thanks
In Drupal 8, using "#markup" is not the proposed method to attach javascript files.
You can define libraries in your custom module or theme and attach the library to your form. The library can contain multiple js and (or) css files.
To define a library in your module:
Suppose your module name is "my_module", create a file "my_module.libraries.yml" in your module folder and specify the js and css files like this
form-script:
version: 1.x
css:
theme:
css/form.css: {}
js:
js/form.js: {}
js/form-ajax.js: {}
dependencies:
- core/jquery
In order to attach this library to your form:
$form['#attached']['library'][] = 'my_module/form-script';
Then clear cache. The js and css files will be loaded in the same order as you mentioned in the libraries.yml file.
You can define multiple libraries in the same "my_module.libraries.yml" file.
#markup still works in Drupal 8, but now it is filtered before output. As it is stated in Render API overview:
#markup: Specifies that the array provides HTML markup directly. Unless the markup is very simple, such as an explanation in a paragraph tag, it is normally preferable to use #theme or #type instead, so that the theme can customize the markup. Note that the value is passed through \Drupal\Component\Utility\Xss::filterAdmin(), which strips known XSS vectors while allowing a permissive list of HTML tags that are not XSS vectors. (I.e, and are not allowed.) See \Drupal\Component\Utility\Xss::$adminTags for the list of tags that will be allowed. If your markup needs any of the tags that are not in this whitelist, then you can implement a theme hook and template file and/or an asset library. Aternatively, you can use the render array key #allowed_tags to alter which tags are filtered.
As an alternative you may use FormattableMarkup:
'#markup' => new FormattableMarkup('<div><script src="http://localhost/project8/sites/all/libraries/test.js"></script></div>', []),
though it is not recommended in this case.

Impresspages ipBlock default widget

Can you set up a default widget to ipBlock(), same as you can create a slot and set defaults in
ipSlot('name',array('id'='id','tag'=>'tag','default'=>'default whatever));
?
No, you cannot set up default widget to blocks. However, you can show your example content.
ipBlock('block-name')->exampleContent('<p>Any HTML you want.</p>');
Most common usage is to create a real widget, copy the source code that is rendered (HTML) and paste as example.
I hope this will help.
I tried this with the following code.
It works fine with IP 4.5.2 and 4.6.0
<?php echo ipSlot('text', array(
'id' => 'my_text_slot_1' . ipContent()->getCurrentPage()->getId(),
'default' => '<img src="http://localhost/ImpressPages/Theme/MyTheme/images/my-image.png" alt="">')); ?>
okay, wrong answer but very nice to set non-static dummy-content into IP ;)

cdetailview and cgridview customise css style in yii

I am using both cwidgets i.e., cdetailview and cgridview I have displayed it using renderPartial method .
The thing thing is That I need to change my css to it for beautification.I am well versed with css styling but to these widgets, how do I apply it in yii? thats the big question to me, I did walk through all forum pages yet my need is not satisfied.
following is the code
viewb
<?php $this->widget('zii.widgets.CDetailView', array(
'data' => array(),
//to avoid error
'attributes' => $res,
'cssFile'=>Yii::app()->request->baseUrl.'/css/mecss.css',));
?>
cssFile doesn't work have copy pasted the assets detailview code and applied my css yet no change
controllerb
$this->renderPartial('viewB',array('res'=>$res));
viewc
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'ajaxUpdate'=>true,
'columns'=>array(
array('name'=>' Name','value'=>'$data["name"]'),
array('name'=>' status','value'=>'$data["status"]'),
),
));
?>
controllerc
$this->renderPartial('viewc',array(
'dataProvider'=>$dataProvider,
));
this is the view what am looking for
all the attributes are from the same table's record which i have provided as $res to detailview but then i need deatils, credential details and expirarydetails as headers for respective attributes .is it possible? if yes please guide else what else can i do so to achieve it please let me know.
am displaying it in modelA and modelD view respectively using ajax
to each i wanna apply my css style but then i dont know how do i start
i do know their's an attribute cssFile am tryng with it can anyone guide for it or any good way.
Please guide let me know how do i achieve it
Yes you can apply your custom Css. Some attributes are used for this like
cssFile
filterCssClass
itemsCssClass
loadingCssClass
pagerCssClass
rowCssClass
rowCssClassExpression
summaryCssClass
And yes here is the demo with custom Css properties.
http://www.yiiplayground.com/index.php?r=UiModule/dataview/gridStyle
you can set all sorts of classes for your CGridView :
class for your row
class for filter row
rowCssClassExpression
a PHP expression that is evaluated for every table body row and whose
result is used as the CSS class name for the row.
The following code will apply CSS class from Bootstrap 3 framework to detail view:
<?php
$this->widget('zii.widgets.CDetailView', array(
'data' => array(),
'htmlOptions' => array('class' => 'table table-striped table-bordered table-hovered table-condensed'),
//to avoid error
'attributes' => $res,
'cssFile'=>Yii::app()->request->baseUrl.'/css/mecss.css',));
?>
Basically, you can use the htmlOptions property to apply whatever style or HTML attribute you want (everthing, based on tag name).

Adding custom code to <head> in Drupal

I'm trying to figure out where the <head> for all of the pages in Drupal is (I'm using Orange theme if it matters). I have to add analytics code into the <head>.
Inside which file would I find the <head>?
Use drupal_set_html_head() by placing this in your themes template.php file. If the function MYTHEMENAME_preprocess_page() already exists insert what is inside the {closure} brackets below (before the $vars['head'] if that exists in it as well) :
function MYTHEMENAME_preprocess_page(&$vars, $hook) {
// say you wanted to add Google Webmaster Tools verification to homepage.
if (drupal_is_front_page()) {
drupal_set_html_head('<meta name="google-site-verification" content="[string from https://www.google.com/webmasters/verification/verification]" />');
$vars['head'] = drupal_get_html_head();
}
}
In template.php of your theme folder :
function your_theme_preprocess_html(&$variables) {
$appleIcon57px = array(
'#tag' => 'link',
'#attributes' => array(
'rel' => 'apple-touch-icon',
'href' => '/images/ICONE-57.png',
'type' => 'image/png',
'media' => 'screen and (resolution: 163dpi)'
)
);
drupal_add_html_head($appleIcon57px, 'apple-touch-icon57');
}
If you look in your theme folder you'll see page.tpl.php, that is the template for the site. You can add the code there most likely.
How to change a page meta description and keywords in Drupal 6
One another solution is to use blocks in header these can also managed very effectively using css.
All you have to do is to go to Structure->Blocks then create new block.
Then select theme corresponding to it and position in which section you want to show that block.
Custom html like can be added. And can be handled from that id.
It allow me to handle page structure very easily.
In the theme folder (e.g. themes/orange) there is a templates folder with the file html.tpl.php
In this file you can freely add what you need to the head section and it will be added to every page.
there is a google analyitics module that will accomplish this for you with just your key.

Resources