In my main layout we got this
<div id="myContent">
<?php echo $this->fetch('content'); ?>
</div>
to render the different views on my app. Also, at /View/Pages/ I have static pages like 'About us', 'Contact', etc.
I would like to know if there is any way to insert the static pages in this place when I do click on the appropriate links.
I think it could be done with JQuery, but the question is if there is any magic in cakePHP to do it. Thanks.
Related
I'm using CakePHP 3.x. I have just installed the source files and the first page that comes up uses the default.ctp layout which calls the home.ctp view. My understanding at the moment is that the view gets placed here in the layout,
<?= $this->fetch('content') ?>
My question is, how come in both the view and the layout some elements and metadata are duplicated. So for instance both call
<?= $this->Html->charset() ?>
<?= $this->Html->meta('icon') ?>
and both duplicate the html structure by using <html>, <head> and <body> tags.
To summarise, if i view the code of the webpage, lots of the structure is duplicated.
Thanks
home.ctp on fresh installed cakephp is just example.
opet that file and see line 22
$this->layout = false;
if (!Configure::read('debug')):
throw new NotFoundException('Please replace src/Template/Pages/home.ctp with your own version.');
endif;
As we see this home.ctp not use layout .ctp, simple clear all code from that file, and add for example:
<h1>This is my new landing page</h1>
save, reload, now your home.ctp use default.ctp layout with meta tags etc..
I am new in drupal. I want to customize and style my login or my registration form.
There are some predefined blocks in Admin|Structure|Blocks. Login form is one of these predefined blocks and I want to show it in a specific region in my page.tpl.php page. the following code in page.tpl.php shows a login form. I want to style it with bootstrap css. How can I do that?
I have searched a lot and found some code in template.php and so on. But none of them worked. :(
Thank You For Your Help!
<?php if($page['login_region'])
print render($page['login_region']);
?>
You can do like this, just typing html and printing the region, then you can add css with your classes, or you can install Block Class Module to add classes to blocks:
<div class="row">
<div class="col-sm-3 customclass"?
<?php if($page['login_region'])
print render($page['login_region']);
?>
</div>
</div>
I am trying to override the front page node, however after following the guide from the official site, it's not working.
Guide: https://www.drupal.org/node/1585528
I have taken node.tpl.php and renamed it to node--front.tpl.php and made changes to the layout, saved and cleared cache. The changes are not being displayed.
Now if I edit node.tpl.php directly it shows the changes, anyone know what I am doing wrong to override specific node templates?
EDIT:
I want to move the title below the image being displayed in the front page.
See below: Moving the title block under the content block, moves the title down as I want it to do, however how do I specify this for just the front page and not all nodes? (renaming node.tpl.php to node--front.tpl.php does not work as mentioned above)
In node.tpl.php: (title block)
<?php print render($title_prefix); ?>
<?php if (!$page): ?>
<h2<?php print $title_attributes; ?>>
<?php print $title; ?>
</h2>
<?php endif; ?>
<?php print render($title_suffix); ?>
(content block)
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
To override the node template for particular node, you need to override the default node.tpl.php. For this copy the existing node.tpl.php file to node--{node_id}.tpl.php.
If you want to override the page template only for front page then you can create page--front.tpl.php file and copy the page.tpl.php file and then modify it as per your requirement.
Still you have issues, then use hook_preprocess_page() in template.php and use dpm() function to find the theme_suggestions that will give the sequence of execution of templates file.
you can use node-{nodeid}.tpl.php
It may help you.
Source: https://drupal.stackexchange.com/questions/39710/how-do-i-define-a-template-file-for-a-specific-node-id
Thanks
Samit K
samitkhulve.com
This is my hyper-link code, everything is working fine but when I click on the last link I can see my view file but after clicking last link I am getting error message when I click rest of the link.My controller name has changed.My main controller name is tutorials. I want to put another controller hyper-link in my my default layout.
Html->link('Home',array('action'=>'index')); ?>
Html->link('Form',array('action'=>'add')); ?>
Html->link('View',array('action'=>'show')); ?>
Html->link('Ajax',array('action'=>'quick')); ?>
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple')); ?>
When you click on the last link you move to another controller, and when you click again on the rest of the links you are going to the Infos controller quick, show, add... methods, and probably they dont exist.
Change the links to this and all links should work through all your site.
Html->link('Home',array('controller' => 'Tutorials', 'action'=>'index'));
Html->link('Form',array('controller' => 'Tutorials', 'action'=>'add'));
Html->link('View',array('controller' => 'Tutorials', 'action'=>'show'));
Html->link('Ajax',array('controller' => 'Tutorials', 'action'=>'quick'));
Html->link('Multiple',array('controller'=>'Infos', 'action'=>'multiple'));
i am working on a Cakephp 2.x .. right now i am loading my js and css files like this
View/Layout/default.ctp
<?php echo $this->fetch('css'); ?>
<?php echo $this->fetch('script'); ?>
<?php echo $this->fetch('scriptBottom');?>
and in each view file i am doing this because there are some pages i am loading different css and js files
for example
View/users/index.ctp
echo $this->Html->script('libs/modernizr.custom',array('inline' => false));
$this->Html->css('reset3860.css', null, array('inline' => false));
echo $this->Html->script('libs/jquery-1.8.2.min', array('block' => 'scriptBottom'));
now the first problem i am facing right now is when i have to write js at the bottom of view page for example if i am submitting a form through ajax .. i can't write at the bottom of the index page ... because if i write there the js will go at the middle or center of the page so now what i do is i go the default.ctp and write there..
so i want to write at the bottom of the index page so it can easily managable and i can see it well what i am doing
the second question is what is the best way to manage all this ... or is there a way that i can make one file of cs and js ... in which there is only the css and js files are loaded ..and then i include that file in my default . ctp page
You should place scriptBottom block at the bottom of your layout, after content block:
<body>
<?php
echo $this->fetch('script');
echo $this->fetch('content');
echo $this->fetch('scriptBottom');
?>
</body>
And then in your views (notice - NO echo):
$this->Html->script(
'libs/jquery-1.8.2.min',
array('block' => 'scriptBottom')
);
$this->Html->scriptBlock(
"alert('Boom!');",
array('block' => 'scriptBottom')
);
here is very good concept and also i have applied in one of my application, it is working very well
it compatible with CakePHP 2.1, and packaged it as a plugin. And also upgraded the CSS compression from CSSTidy to the more recent and better maintained CSS Min.
The plugin is quick and easy to install. The installation instructions are somewhat long - but that's just to provide clarity.
for detail view you can refer Detail link Cakephp.org also you can see the plugin document and how to use it in your appliation