Preventing a specific CSS file from getting loaded in Yii - php

I am coding in Yii.
I have registered the main.css file in my main.php layout file like so :
Yii::app()->clientScript->registerCssFile($this->assetsBase.'/css/main.css');
Now this script is being registered in all the pages. However, say I don't want that script to be registered on a specific page.
I know that using :
Yii::app()->clientScript->reset();
would remove all the CSS files, however I want only few CSS files to be unregistered.
Is there a way to do it?

You can use the scriptMap property of CClientScript in your specific view, passing false for the particular script/css file's key that you don't want to be rendered. From the doc:
The array keys are script file names (without directory part) and the array values are the corresponding URLs. If an array value is false, the corresponding script file will not be rendered.
For example, in say views/site/pages/about.php:
Yii::app()->clientScript->scriptMap = array(
'main.css' => false
);
to disable the inclusion of main.css registered with registerCssFile.
The scriptMap can also be used for controlling the rendering of js script files.

I would suggest either:
Using a separate layout for that page like main_no-css.php
or
Adding a condition before registering the script (like if controller != xxx and action != yyy), but this would cause the condition to be checked on every other page.
I would definitely go for a separate layout.

Related

Broken SilverStripe Template

For some reason, after doing a ?flush=all, a certain page type is not able to locate it's default template. I figure out that it's not loading it's template file after appending showtemplate=1 to the URL. The dumped raw template shows nothing for the default template.
Pastebin: http://pastebin.com/uMLefAsP
I wish someone could point me to the right direction here, for I have no idea where to start debugging.
Thanks, Jan.
Firstly, and I have to ask: Is there actually a PageType called "CommunityExtensionPage"? PageTypes need to be named the same as the required template, for the template to be picked-up automatically.
You seem to have two template files "CommunityExtensionPage.ss". One at "templates/CommunityExtensionPage.ss" and one at "templates/Layout/CommunityExtensionPage.ss"
It would be useful to see the contents of both files. SilverStripe will look for "CommunityExtensionPage.ss" in the top-level of the "templates" dir before looking in "templates/Layout".
If "templates/CommunityExtensionPage.ss" is found, it will also try and look for "templates/Layout/CommunityExtensionPage.ss" and render this into the $Layout template variable. Otherwise, it'll use the default "templates/Page.ss" and request "templates/Layout/CommunityExtensionPage.ss"
Does your "templates/CommunityExtensionPage.ss" template contain a reference to $Layout? If not, then the contents of "templates/Layout/CommunityExtensionPage.ss" will not be rendered.

How to make a template overwrite for mod_menu with alternative layouts for link outputs?

I understand and love template overwrites. I need to do some heavier changes to the menu output (basically making the output work better with Bootstrap) - but only for certain menus.
Currently in Joomla 3 there are the following in the mod_menu/tmpl folder:
default.php
default_component.php
default_heading.php
default_separator.php
default_url.php
If I want to change the classes I'd copy the default.php into my mytemplate/html/mod_menu and change it. Great, no problem.
If I want to change the link outputs to go along with that I can copy the default_component.php to mytemplate/html/mod_menu and change it. Great, no problem.
If I want to have the choice of having a different "Alternative Layout" I'd rename the mytemplate/html/mod_menu/default.php to newlayout.php, then select it in the admin module manager for that menu. Great, no problem.
Here's the problem: If I want to have the link output changed for certain menus but not all of them I figure I'd change default_component.php to newlayout_component.php like I did above which would correspond to the newlayout.php...but that doesn't work.
Questions:
1) How to have alternative layouts for each of the default_component.php, default_heading.php, default_separator.php, default_url.php template files (not just an overwrite)?
2) I would think default_url.php is the one that would affect the link outputs but it seems it's default_component.php that does. So what does each one of those do? I couldn't find any information on joomla.org about that.
Thanks!
The alternative layout feature only works for the main file (default.php), not for the sublayouts (default_component.php, ...). So you have to create your own newlayout.php which then can load newlayout_component.php, or use the default_component.php. In fact, the default_component.php will be used as fallback if no newlayout_component.php is found.
The code switches over the $item->type of the link. 'separator', 'url', 'component' and 'heading' are handled by the 'default_'.$item->type, everything else will use default_url. So a plain URL should indeed be generated by default_url.php, not default_component.php. If it behaves differently, it's likely a bug.

Theming and layout in yii framework

I am a newbie in Yii Framework and creating a CRM which is module based.
Using different tutorials I am able to create my own theme, but now I am stucked at one point.
In my theme, the upper <nav> and left <nav> remains the same throughout the app, until user is logged in. That's why I made it a part of my main.php, but in the login page there are no buttons to show, just simple login form with 2 textfields.
How can I implement this form in my application using custom themes?
I have tried to define a layout in that particular action but not succeeded. Any help would be appreciated.
Using a custom layout for your view is the right way to go.
You can either set the layout in the controller action or in the view.
$this->layout = "//layouts/mylayout";
Note that the default layouts column1.php and column2.php also use the main.php layout file.
Try this step by step :
Create New theme
You can create a new theme and add this to the directory
Application_Root/themes.
Look at the themes/classic directory to get an an idea of the structure of the directory.
The important file (at this stage) is :-
Application_Root/themes/views/layouts/main.php
Customise your theme contents
Copy the css, image, js files etc to the correct directory and change the main.php file to your liking. For example, if your main.php says
<link href="css/mystyle.css" rel="stylesheet">
Then you will have a file
Application_Root/css/mystyle.css
Create the content placeholder.
Somewhere in your main.php, there will be a placeholder for dynamic text, which is specified by.
<?php echo $content; ?>
Tell yii to use the theme.
Change the file Application_Root/protected/config/main.php by adding the following line just before the last line (containing the closing bracket).
'theme'=>'surveyhub'
Create the layout placeholders.
Create an HTML segment that will be written into the $contents portion of main.php. Call it for example one_column.php. The file path will therefore be Application_Root/themes/views/layouts/one_column.php In that file, where you want the dynamic text to be placed, create a placeholder.
<?php echo $content; ?>
Tell Yii to use the layout.
In the file Application_Root/protected/components/Controller.php, add or modify the layout variable to read :
public $layout='//layouts/one_column.php';
Refresh the page

opencart - How to manually display a module inside a template file?

Let's say I want to display the specials module on the homepage in a position different than $content_top, $content_bottom, $column_left or $column_right. How do I do that? If you have some experience with this, could you give me some pointers?
The module will be display in home.tpl but I'm assuming I would need to edit the controller file home.php
To do this, you will need to make edits to two files
Firstly, you will need to edit the controller. In this example, I'm going to add the specials to the home page
So open the controller file catalog/controller/common/home.php. Somewhere before this line $this->response->setOutput($this->render()); add the following
$this->data['special_block'] = $module = $this->getChild('module/special', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80
));
The array is the settings for the module. Note that the layout, position, status and sort order aren't included, as they're irrelevant here. I've also used special_block as a unique key for the content, to avoid it conflicting with any other items that may need rendering
Then in your template file, you just need to use <?php echo $special_block; ?> wherever you want the module to go

ViewScript decorator unable to set

I am following the section about "Full Customization Using the ViewScript Decorator" from this page -> http://devzone.zend.com/article/3450
In the init method of my form class I have added this
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
Now in the place where my form appeared I have this:
An error occurred
Application error
What am I doing wrong here? I really need to customize the appearance of the form and I just want to change the form and not the appearance of the whole page.
I have tried this:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
Which works but affects the display of the whole page (I am using zend layout). I just need the render of the form to be passed to the display.phtml page.
Note: Is there any place in particular I have to place the display.phtml? I placed it in the view\scripts folder.
I think it is as simple as this.
The ViewScript cannot be used in the init() method for your form for one simple reason. If you look at the example (and probably your display.phtml) there are echo statements like this one $this->form->firstname;. At this point in init() the form elements are not loaded yet!
The author therefore correctly shows this code
$form->setDecorators(array(
array('ViewScript', array('script' => 'demogForm.phtml'))
));
Note that he uses $form as the object. Either in controller or view script you load your form as an object and then add the ViewScript. So in one of your controllers you would do something like this
$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
array('ViewScript', array('script' => $scriptPath))
));
This should do the trick.
Update Looking at the naming of your pthml I assume (and hope) this is a special template for your form and not your whole layout file. If you use your whole layout file then of course if will render the whole page!
When working with view scripts, I find it's best to make any such changes at the view level.
Ignore the "ViewScript" decorator details in your form and set them from the view, eg
<?php echo $this->form->setDecorators(array(
'PrepareElements',
array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>
The location of the display.phtml file is relative to the module's view scripts folder. If this is just the default module (under the application folder), the script in my example will be located at application/views/scripts/_forms/display.phtml
If you want to remove HTML tags like <dt> or <dd> (labels and viewscript) you can use methods removeDecorator('HtmlTag') or removeDecorator('Label')

Categories