Yii module, theme layout include module layout. How to to that? - layout

I need do something like that:
I have theme "panel" in /themes/panel and there layout /themes/panel/views/layouts/main.php with example content
<a>$content</a>
I have module "admin" in /protected/modules/admin and there layout /protected/modules/admin/view/layouts/main.php with example content
<b>$content</b>
And on the end i want
<a><b>view</b></a>
Also in /themes/panel/views/layouts/main.php i need load css file from module.
In other explanation:
I have one template for all panels (header, css files, footer), but each of panels need separate layout (only the middle of content change like menu etc.) and one or more individual css file.
Also some images will be include from main theme, other will be individual for modules.

You can use the renderPartial function for load the parts of layout.
<?= $this->renderPartial('webroot.themes.' . Yii::app()->theme->name . '.views.layouts.' . Yii::app()->layout . '.<PART_OF_LAYOUT>') ?>

I disagree that in many help forums of the Internet, when someone asks abot theming a module, everyone suggests a path alias to the themes folder. I think this is wrong, because it implies modules to be splitted, and modules are supposed to be a black-box that can be used across projects. The advice given in such forums would only be valid if a theme is shared among several modules. If someone wants to "package" a theme inside a module, she can:
-add an init function to the controller of the module
-inside that init, use the class attribute layout and a path alias, like this, supose a module whose id is "Sample":
then you add, to SampleCOntroller.php:
public function init() {
//BELOW: it will use the layouts/main.php inside the module.
$this->layouts = "sample.views.layouts.main";
}
Yo can check about path alias here:
http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace

Related

Removing Bootstrap 3 default styling

For a recent site, the client has 5 different brand styling colours. So to keep track of everything in the less files (which we use node to compile to one final css file), I've defined the colours as less variables and used the .button-variant() mixin to generate the styles. e.g.
#color-cta-light: #df134d;
#color-cta-dark: #860c2f;
#color-cta-background: #fcf7fa;
.btn-cta {
.button-variant(#ffffff, #color-cta-light, #color-cta-dark);
}
That works fine. However, I've done this with panels as well, and I've now ended up with an 11,000 line long css file. It is this long because we need the majority of the default Bootstrap styling (such as .btn styling) as well as my custom styles.
What I am wondering is, (and keeping it simply by using just buttons as an example) is there a good easy way to remove the lines in the css that pertain to the default Bootstrap button styling, i.e. btn-success, btn-warning, etc. By easy, I mean automatically. We're using the node lessc modules to compile the less files (using a grunt watcher), so I imagine whatever it is that would need to happen would be run after the compile.
Alternatively, should I just amend the default bootstrap mixins to do nothing, and use my own custom mixins? I feel like that should work but that would mean a bit of extra time each new version of Bootstrap (currently 3.1) spent making sure that the custom mixins are up to date.
What I'm hoping to end up with is a single stylesheet, with default button styling from button.less without the additional overload of unused CSS. With my understanding, it's not possible but I'm hoping there are some tools out there that I don't know of that would help my situation.
If I understand you correctly, looking at both your question and your comment to Bass Jobsen, you want to keep Bootstrap styling, but not for the "button styling."
I believe the LESS (reference) feature is still what you want, but just selectively applied.
Assuming you are using the "bootstrap.less" file, add the reference notation just before the "buttons.less" file, like so (I've elided much of the normal "boostrap.less" file for brevity):
// Core variables and mixins
#import "variables.less";
#import "mixins.less";
...
// Core CSS
...
#import (reference) "buttons.less";
// Components
...
// Utility classes
#import "utilities.less";
#import "responsive-utilities.less";
This will totally deactivate all classes from "buttons.less" from being generated in your output css code, but still keep those classes available for mixin purposes. Should you need a particular piece from that code, let us say you wanted to keep the base .btn class, then you would have to add it back into your css, like so:
.btn {
.btn;
}
The outer .btn will reform a class in your code, while the inner .btn will use the referenced "buttons.less" .btn to generate the code.
Using (reference) in this way lets you selectively remove aspects of boostrap by module, while keeping those aspects accessible for the rest of bootstrap and for any mixin uses you have for it. This is probably a preferable method if you desire to remove most of the code from a module (if you actually wanted to keep most of the code, it would probably be best to just let the unused portion remain and import it normally).
You can use import with reference:
#import (reference) "bootstrap.less";
#color-cta-light: #df134d;
#color-cta-dark: #860c2f;
#color-cta-background: #fcf7fa;
.btn-cta {
.button-variant(#ffffff, #color-cta-light, #color-cta-dark);
}
This will give you only the CSS for you button. (and some :before : after pseudo classes which seems a bug for me).

How to display modules only on search results in Joomla 2.5?

Hello please read the whole question, this isn't just solved by enabling the modules only for the search page:
I have a few modules that are exclusively shown on the search page in Joomla.
I created a hidden menu entry for the search as well in order to tell modules to only show on this page. This works alright, but when I click one of the results and get redirected to the actual result, then the modules, which should only show up on the search page are still shown in the result page.
Any clue how to fix this? Really annoying as I use 3rd party search enhancing modules, and they are showing on the results.
Using standard Joomla, there's no way to target modules to only the search results page and none of the pages that link off the results – but I know you knew that! The hidden menu item is a help, but does not change the menu item of some of the links off that page. It's all to do with the allocation and use of "Itemids" in Joomla.
To be able to target modules more specifically, you need to use a 3rd-party extension. I developed MetaMod (www.metamodpro.com) to cope with exactly this use case. MetaMod is a wrapper module that can then decide just which other module to include in itself (or not). So you assign the MetaMod to the page, then put a snippet of code inside the MetaMod which decides which other module to include.
In this case, I'd use the following in MetaMod:
if ($core_genius->check("pagetype = search, searchresults")) return XXX;
// replace XXX with the module id of the module to include
// ONLY on the search page, or the searchresults page, but
// no other type of page.
Hope that helps,
Stephen
Although MetaMod is great (I've used it myself & Stephen's support is great!) there is another way to do it without using 3rd party extensions.
You could create new module positions in your template above (or below) the module positions you wanted to use and wrap them in an if statement like so:
<?php if(!isset(JRequest::getString('searchword'))) : ?>
<jdoc:include type="modules" name="right-search" style="xhtml" />
<?php endif; ?>

Path to layout xml files in magento

I have seen that we can place our layout xml files in
app/design/frontend/default/default/layout
or we can place our customization inside
app/design/frontend/base/default/layout/local.xml
file, but I have read at magebase and at magentocommerce that we can place our layout files under
app/design/frontend/your_interface/your_theme/layout/
or
app/design/frontend/[package]/[theme]/layout
So if we I have package like 'Kaushikamdotcom' in 'app/code/local', should I have to create that same package under 'app/design/frontend/' ? I tried many patterns, but nothing worked out for me.
I am quite sorry that I have made such a blunder asking this question, but I am answering this as lots of people will be making the same mistake. Package means; in the admin side of magento open
System->Configuration->Design
Then change the configuration scope to Main website. Then select Package section, uncheck the default check box and use your package name such as "Test". Then create the following folder structure.
app/design/frontend/Test/default/layout
Place your layout xml files here. If you are using your own themes use that name instead of default.
It depends what layout-xml file you have.
If you want to build up your theme, use the local.xml file in your theme dir.
If you write an extension and want to add a block to use inside this new extension, add a layout-xml file via config.xml and add it under base/default/layout/yourname.xml
When you do it this way, your theme-related changes only appear in the theme and your extension-related changes are theme-independent

Is there a function in Orchard CMS that will retrieve the Theme directory?

I have images in my theme (in the Content/ directory) and I want to show them in different places.
My current approach is : <img src="#Url.Content("~/Themes/MyTheme/Content/Images/image.gif")" />
This works, but is not very maintainable (what if I want to switch themes, etc).
Is there an built in method, something like GetCurrentThemeDirectory() that would return the directory so I could do or something like that?
Edit: from mdm's comment, I realize that changing the theme isn't a valid concern. I really just want to avoid typing out the url for every reference
Where are you referencing the image from? Module? Another theme?
If it is from the theme that has the image, then you don't need to worry about switching themes. If it is from another theme, then the image should be a part of the theme. If it is from a module, then it would make sense to store the image as part of the module or override it in the theme (see below).
If you wanted to have the image as part of the theme, then you could have the module return a 'default' shape and then override that in the theme. There really shouldn't be any reason to reference the theme's images from a module or vice versa.
Edit after your edit
In the themes I've written, I've followed what the Orchard authors do. Rather than using <img> tags, images are placed in Styles/images. They can then be referenced using the CSS background-image attribute.
In Views/Branding.cshtml:
<div id="header"></div>
<h1 id="branding">#WorkContext.CurrentSite.SiteName</h1>
And then in site.css:
#header {
/* snip */
background-image: url(images/header.png);
/* snip */
}
Themes/TheAdmin/site.css contains plenty more examples of this method.

silverstripe - adding styles to 'styles' drop down menu on editor

from the question above, I thought it would be relatively easy but i can not find any documentation on on how to add styles to the 'styles' drop down menu. can anyone push me in the right direction?
The styles dropdown is automatically populated based on classes found in your theme's typography.css file. To add classes, just ensure that they are defined there. Alternatively, if you want to give the classes friendlier names or to remove some classes from the list, you can explicitly define the styles that you want listed by putting this in your _config.php file.
HtmlEditorConfig::get('cms')->setOption('theme_advanced_styles',
'Name 1=class1;Name 2=class2');
It's a feature provided by TinyMCE, the WYSIWYG editor component, and this line is just setting the theme_advanced_styles setting of TinyMCE when used by the CMS. This thread on the TinyMCE site also discusses it.
Also note Markus' answer below: editor.css needs to be in the theme css folder and include the typography.css.
The answer of #Sam Minnée only works, if the editor.css is also in the theme css folder and includes the typography.css.
Here is a more detailed description of how these two play together.
If you have troubles getting the new styles appear in the editor, try the following:
yoursite.com/admin/?flush=1
Check the file permissions on your mythemes/css/editor.css file. It should be readable by the webserver user.

Resources