I am trying to integrate a custom theme on YII2 basic app.
I have two layouts, the main layout and other is login layout.
Now I don't need a css file say xyz.css on login layout but it gets loaded there and my design is getting messed up. Any proper way of disabling it on that one layout?
I am registering my css files from AppAsset.php file.
the css section look like
public $css = [
'themes/mytheme/assets/css/xyz.css',
'themes/mytheme/assets/css/main.css'
];
Step - 1: Create LoginAsset.php in assets Folder.
LoginAsset.php
In this file, Keep those .css & .js which is required for login.
<?php
namespace app\assets;
use yii\web\AssetBundle;
class LoginAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'css/include-your-css-if-any.css'
];
public $js = [
'js/include-your-js-if-any.js',
];
}
Step - 2: Since, you told that you are having one more layout i.e. login layout. So, Use LoginAsset.php in your login layout, Like:
login.php (One out of two layouts i.e. main/login.php)
<?php
use yii\helpers\Html;
use app\assets\LoginAsset;
LoginAsset::register($this);
?>
<?php $this->beginPage() ?>
.
. // Your code
Step - 3: If even though it didn't worked. Then,
Include
<?php
use app\assets\LoginAsset;
LoginAsset::register($this);
.
.
?>
on top of your view file.
Related Search
Two Different Layouts For Guest User & Logged In User-Yii2
Related
I could add extra functionality to a dataobject if I extend it with a dataextension. For example I've got an Item which gets extended from a module with stock keeping functionality. Let's say the Item also gets's extended form a few other modules.
After the extension with the stock keeping functionality, I'd like to display the availability of the item in the frontend, for example with a green/red dot. How can I get this dot's markup inside my template for the detail page(ItemPage.ss) and the include (Item.ss) for the overview page of items without overwriting the whole template. Just adding this one part, like the way I extend a function on my base class?
That could be a way to add extra markup to the original template.
Inside dataobject or global dataobject extension
public function ExtraTemplateHTML($position) {
$html = null;
foreach($this->owner->extend('updateExtraTemplateHTML') as $positionBlocks) {
if(isset($positionBlocks[$position])) {
foreach($positionBlocks[$position] as $htmlBlock) {
$html .= $htmlBlock->getValue();
}
}
}
return $html;
}
Inside the specific dataobject extension
public function updateExtraTemplateHTML($htmlBlocks) {
$viewer = new SSViewer(__CLASS__);
$html = $viewer->process($this->owner);
$htmlBlocks['bottom'][] = $html;
$topHtml = HTMLText::create();
$topHtml->setValue(123);
$htmlBlocks['top'][] = $topHtml;
return $htmlBlocks;
}
Original Template
$ExtraTemplateHTML(top)
...
...
$ExtraTemplateHTML(bottom)
Extension Template
Than just write a new template for your extension with the content you would like to add.
You cannot partially change a template, you can only substitute the template with another. So, keeping this in mind you should keep modular architecture with many logical includes.
Another possible way to extend existing content is using DOM and javascript. But you should think about side effects. For example if you add extra textual content then it won't be visible by crawlers and will effect your SEO. But for decorative enhancements, like adding extra coloured dot, this approach will work.
I want to change different logo for each different pages in drupal and I also want to hide logo for some pages too.How can I do that?I've already search possible answers and I didn't find any.
As was stated by MilanG, logo is rendered in your page template (default page.tpl.php or theme suggestion) using $logo variable. This variable is set in template_preprocess_page(), and the best way to change it is to use the same preprocess function in your theme:
function mytheme_preprocess_page(&$variables) {
$logo_path = '/' . drupal_get_path('theme', 'mytheme') . '/logos/';
// Alter logo under some conditions
if ($first_condition) {
$variables['logo'] = $logo_path . 'logo1.png';
} elseif ($second_condition) {
$variables['logo'] = $logo_path . 'logo2.png';
} elseif ($third_condition) {
// Hide logo. Your page.tpl.php must contain
// something like <?php if ($logo): ?>
$variables['logo'] = null;
}
// etc.
}
The "standard" way for printing logo is printing $logo variable from page.tpl.php template. But you don't have to do it that way at all.
I.e. you can add your php code which will alter logo html code the way you like.
Or, you can place logo html inside static blocks and set for every block on what pages should it appear (in block settings). And of course create "logo" region for your theme.
I have removed the base_tag from my template to allow for the use of SVG icon sprites. A side effect of this is that images on pages other than the home page break.
The HTMLEditorField::saveInto() method is forcing a relative url on the image and they end up pointing to /some-page-other-than-home/assets/image.jpg which is wrong.
How do I get images to resolve to the root /assets/ directory rather than pointing to /some-page-other-than-home/assets/.
SilverStripe provides extension hooks on some methods. The HTMLEditorField has a 'processImage' hook that you can tap into.
You can hook into this method with the following:
1. Create your extension configuration.
/mysite/_config/Config.yml
HtmlEditorField:
extensions:
- HTMLEditorFieldExtension
2. Create a the HTMLEditorFieldExtension class.
/mysite/code/HTMLEditorFieldExtension.php
<?php
class HTMLEditorFieldExtension extends DataExtension
{
// This method name must be the same as the extension hook
public function processImage($image, $img) {
// Get the image src attribute
$src = $img->getAttribute('src');
// Concatenate a leading slash
$img->setAttribute('src', '/' . $src);
}
}
3. Run a dev/build.
This needs to be done so SilverStripe can find the new extension. After this your images should now have the missing leading slash.
My website is www.kipclip.com and it's running on Kohana. I created a new rental page. But it's not taking my CSS and JS files. I tried to find how this is included or if Kohana has a special method for do that. But still not successful. Do you have any idea regarding this?
A quick and dirty way to do so is to tack on the name of the script(s) and style(s) in the view you're implementing using regular html script and style tags and go on from there.
But, if you don't like quick and dirty, and prefer to do it better and more concrete, if you use Kohana 3.2, you can do the following. I haven't tried this on the older or newer versions, so it may or may not work in them (If you try to port it to that version, consult the transitioning document relative to the version in question that you wish to port):
/**
* /application/classes/controller/application.php
*/
abstract class Controller_Application extends Controller_Template {
public function before() {
parent::before();
if($this->auto_render) {
//Initialize empty values for use by ALL other derived classes
$this->template->site_name = '';//this is a psuedo-global set in this class
$this->template->title = '';//this too is set by the controller and action
$this->template->content = ''; //this is set by the controller and action
$this->template->styles = array();
$this->template->scripts = array();
$this->template->admin_scripts = array();
}
}
/**
* The after() method is called after your controller action.
* In our template controller we override this method so that we can
* make any last minute modifications to the template before anything
* is rendered.
*/
public function after()
{
if ($this->auto_render) {
//set the CSS files to include
$styles = array(
'style1', //the css file with all the defaults for the site
'jquery-library-css'
);
//set the JavaScript files to include
$scripts = array(
'myscript1',
'myscript2'
);
$admin_scripts = array(
'jquery-admin-functions',
);
//now, merge all this information into one so that it can be accessed
//by all derived classes:
$this->template->styles = array_merge($this->template->user_styles, $user_styles);
$this->template->scripts = array_merge($this->template->user_scripts, $user_scripts);
$this->template->admin_scripts = array_merge($this->template->admin_scripts, $admin_scripts);
}
//bind the site_name to the template view
$this->template->site_name = 'My Site Name';
//OLD WAY shown below:
View::set_global('site_name', 'My Site Name'); //set the site name
//now that everything has been set, use parent::after() to finish setting values
//and start rendering
parent::after();
}
}
So, how does this work? Remember that the application.php class is the base controller class from which all other controller classes are derived from. By implementing this type of binding to the base controller, every derived controller has access to what scripts, styles, etc. are available. And, as a result every associated view called by that controller also has access to those variables.
So, now to access those variables in your view:
Example, the template PHP file: /application/views/template.php
If it's defined like this (using PHP short tags - but do not use short tags in production code!):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html>
<head>
<meta charset='utf-8'/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<?php
/**
* Link the css files stored in the `static` folder from the project root.
* This will vary depending on how you have your files saved.
*/
foreach($user_styles as $style) : ?>
<link rel="stylesheet" href="<?php echo URL::base() . 'static/css/' . $style ?>.css" type="text/css"/>
<?php endforeach; ?>
<?php //Create AND set a dynamic page title - much like Facebook ?>
<title><?php echo $site_name; if(!empty($title)) echo ' - ' . $title; ?></title>
</head>
<body>
<!-- Fill in the body with HTML, PHP - whatever you want -->
<?php
/**
* Now, load the scripts:
* According to Yahoo, for better site performance, all scripts should be loaded after the body has been loaded
*/
foreach($user_scripts as $script) : ?>
<script src="<?php echo URL::base() . 'static/js/' . $script; ?>.js" type="text/javascript"></script>
<?php endforeach; ?>
</body>
</html>
There are two takeaway points from all of this:
One: If you want something to be global, or available to all controllers (and subsequent views), define them and bind them in the base application controller class.
Two: As a result, this functionality also gives you tremendous leverage and power in that if you have derived classes, you can them implement this same type of binding to that particular controller class making it available to any subsequent derived controller classes. That way, if you have two classes that should not have access to certain files and their associated functionality, e.g. an admin JavaScript file that loads all posts by some user, then this kind of implementation can make your life much, much, much easier.
And, a third hidden option is that give Kohana is PHP, you can use regular vanilla PHP / HTML in an associated view if you can't figure it out immediately. Although, that is something that I would dissuade you from doing in production code.
Whichever way, I hope this can assist you.
I'm working on a new Moodle Assignment plugin.
How can I include a custom CSS to my plugin?
I'm using Moodle 1.9.7.
Thanks in advance.
just add a file called styles.php into the Module's folder.
the file should output CSS code when it is parsed.
Moodle goes into each Module's folder and looks for that file, when the page's CSS layout is constructed.
Some themes can ignore these files using a special setting in the theme's config.php file
$THEME->modsheets = true;
/// When this is enabled, then this theme will search for
/// files named "styles.php" inside all Activity modules and
/// include them. This allows modules to provide some basic
/// layouts so they work out of the box.
/// It is HIGHLY recommended to leave this enabled.
here is a short sample of what could be the content of this styles.php file:
/* simple CSS code */
.left { float:left; }
/* php that generate CSS code */
< ?php if ( right_to_left() ) {echo ".right:text-align:left;"}
else {echo ".right:text-align:right;"} ?>
Perhaps could take a look at the function print_header_simple() defined in lib/weblib.php.
If you are writing a module which generates module specific pages, and they use the normal moodle libraries then stick something in $meta to be added to the <head> section while the page is being generated.
in lib/weblib.php:
function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='', $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
This means that you probably want something like the following in your module:
$extra_css = $CFG->wwwroot.'/theme/SUPA4/supa_report.css';
$extra_css_meta = '<link rel="stylesheet" type="text/css" href="'.$extra_css.'" />';
print_header_simple($mytitle, "", $navigation, "", "", true, "", navmenu($course), '', $extra_css_meta);