How to import a view to cakephp default layout - cakephp

I am new to cakephp...I have a user add form (add.ctp) and would like to display this form in my default layout (default.ctp)

Aren't Elements the thing you're looking for?
http://book.cakephp.org/2.0/en/views.html#elements

In your default layout there should be a line:
print $this->fetch('content');
If this line is there than cake will automatically include the needed view based on the url and routing.

Related

hide right sidebar on specific pages in drupal

I want to remove the sidebar from the specific page and all its subsequent pages in Drupal 7
My code is mention below.code is in mytheme_preprocess_node(&$variables) function
if ($variables['type'] === 'project'){
$node = $variables['node'];
if($node->type=='project'){
//print_r($node);
echo $node->type;
unset($page['sidebar_second']);
}
why don't you create a tpl file for that specific content type and remove the sidebar from there ? just an idea
Try restricting the block in Blocks UI or with the Context module.
You can restrict that sidebar content in admin panel itself. login as admin and configure that sidebar block to display only on perticular url.

Cakephp 2.0 Pagination with dropdown

I am doing pagination in cakephp. By default there is a list in
"$this->Paginator->numbers" but i want some changes in pagination design so i want all pages in dropdwon and current page is selected in dropdown. I successfully get the dropdown by writing the following code but the problem is that when i click on the page it wil not change
thanks in advance
`
< select>
echo $this->Paginator->numbers(array('tag'=>'option'));
</select>
`
You have to bind event onChange to your select element with JS. It should redirect you to selected page. You can see how to construct jump url in cake's documentation. You can also use this solution but notice it was written for cake 1.x and will need some changes.

How to call CSS for home page in drupal?

A drupal 7 based website has a custom home page. Presently, the whole drupal website has one css called
style.css
. I have written a new css just for home page. Being new to drupal, I have no idea how to specify to home page to use custom css. How to use <link rel....> kind of thing?
Thanks
Not sure why you would want to do this rather than just using different classes but if you really need to you can add a template.php file to your theme. In there use the hook_preprocess_page to add a new stylesheet depending on the homepage. Change YOUR_THEME to your themes name.
function YOUR_THEME_preprocess_page(&$variables) {
$homepage_id = YOUR HOMEPAGE NODE ID;
if (isset($variables['node'])) {
if ($variables['node']->nid == $homepage_id){
drupal_add_css(path_to_theme() . '/css/homepage.css');
}
}
}
I don't think this is the way to go.
If you customised the homepage, you could add a wrapper with a class specific for the homepage.
Then you could target that class with the style.css file and apply specific styles to the homepage.
Sincerely,
dimitril
Most themes have classes built into the body tag to designate "is front". That said, the proper way to do this is to open up template.php in your theme folder and add this code:
function YOURTHEME_preprocess_node(&$variables) {
$node = $variables['node'];
if (drupal_is_front_page()) {
drupal_add_css(drupal_get_path('theme', 'YOURTHEME').'/css/homepage.css', 'theme');
}
}
You'll replace YOURTHEME with your themes name.
Use the CSS tag .front to target only the homepage in Drupal 7. This works fine for me.
This example will target only the side bar second in the home page:
.front .region-sidebar-second{
background-color: #E9EDF2;
}

How to generate 'a href="javascript:void(0)"' like link in cakephp?

How to generate 'a href="javascript:void(0)"' like link in CakePHP?
I make an application, the content will insert into the editor textarea when user click a list of image. I add a class to these images and write some code in the javascript file. Everything is going well.
But the link of the image is a URL address, but not 'href="javascript:void(0)' like URL. Anyone could tell me how to make it in CakePHP?
Thanks in advance!
<?php
echo $this->Html->link(
'/path/to/image/',
'javascript:void(0)'
);
?>
You can either set a path to the image or use the Html helper to generate the image tag code. The second parameter will set the href.
Don't believe there is any dynamic way, however when you are creating your form element you can set it in the options array 'href' => 'javascript:void(0)'

How to modify login.ctp

I'm a newbie to CakePHP and i'm trying to modify the login.ctp so that it would go to a different DIV tag. I already have a default.ctp layout placed in /views/layout but i don't want the menus to appear on the login page when you bring up the site. How do i go about doing it?
Thanks,
Lyman
make a login layout that has no menu, and in login(), set $this->layout= 'login';
in login function, save variable:
$this->set('nomenus', true);
in default.ctp check
if( empty($nomenus) ) {
... menus ...
}

Resources