I wish to add a "Last updated" on my web site (a text automatically showing when my site's content was last up dated).
I found some answers on Drupal forum, unfortunately they all concern Drupal 6 and I simply couldn't get them to work on Drupal 7...
Since I know about nothing about PHP, and I belive it requires to add some PHP code, thank you very much if the answer could be "as simple as possible", and very "step by step" :o)
Thanks for any help!
Based on Muhammad's answer I was able to get this to work in Drupal 6. I just needed to modify a little.
<?php print "Last modified date: " . format_date($node->changed, $type = 'small'); ?>
You can use the node.tpl.php template and use the following line
<?php
print "Last modified date: " . format_date($node->changed, "short");
?>
Hope this helps... Muhammad.
Not all template files always have a $node object in scope (e.g. page.tpl.php when used to render the user page does not).
If, for instance, you want to the "Last modified date" line into page.tpl.php to have it the page footer, you need to make sure that you only call format_date when there is a $node object in scope.
This is how this should look like for Drupal 7:
<?php
if (isset($node->changed)) {
print "Last modified date: " . format_date($node->changed);
}
?>
Related
In the index action of my UsersController I want to pass strings and arrays to view, so that my View is render correctly. I don't know what am I doing wrong but my view file is not getting one of my array to view.
$users = $this->User->getUsers();
//Setting all variable that are present in layout
$this->set('title_for_layout','Users - Admin');
$page_headings = array("text" => "Users", "clss" => "icon-head");
$this->set('page_heading', $page_headings);
//Ends here
//This is actually going to action view file
$this->set(compact('users'));
My View file Code is like this
<div><?php echo $page_heading[0]['text']; ?></div>
<?php foreach($users as $user){ ?>
I am able to get $users variable here but noting getting $page_heading.
I am getting this error Undefined variable: page_heading.
I have tried everything like these:
$this->set($page_headings);
$this->set(compact('page_headings');
and yes I have change my variable name in view file also to page_headings after doing above code. I am not able to get it working. Can Please anybody help.
Thanks in advance.
This was happened because I was editing my live server file directly from filezilla's edit option and when I was saving it after editing file, it was somehow becoming the one line code and because of the comment tag all code that I had edited became comments.
I rectified this problem when i took fresh copy from server.
So what I learned today: After say working about half an hour on file, take updated file from server if you editing from filezilla because you don't know how it gonna save the file.
Thanks ndm for your help.
I updated views in drupal 7 and am getting rogue "?>" symbols rendering on my pages for regions I created in a zen sub theme.
The code for one of the regions follows:
<!--/#adbanner-->
<?php if ($page['adbanner']): ?>
<div id = "adbanner" role = "banner">
<?php print render($page['adbanner']); ?>
</adbanner><!-- /#adbanner-->
<?php endif; ?>
Okay, let's try to debug this:
Start by deleting all of your content from your files (do it with a ctrl + a, ctrl + x and then paste it into a new file - this way we can be sure that ALL of the content is gone). Save the files and render the page.
If the symbols continue to pop up, it is an encoding marker that you will have to turn off. If they stop, it is not an encoding issue and we will have to try something else.
NOTE: When I say delete all of the content, make sure that you keep the structure, i.e. the calls to load any external files. Just make sure that the visible content of those files is removed.
I want to display the tag category of nodes before the title, the title field is unavailable in interface, is there a way to do that in node.tpl.php or page.tpl.php (I won't install another module like ds suite just for this purpose).
PS: I want to do this everywhere node is displayed.
You could:
In your page.tpl.php where your title is echoed wrap the title in an if statement to not display $title if you are in a node page e.g
if(arg(0)!='node'):
if ($title ):
print $title;
endif;
endif;
//print title only if i am not on node pages
and now you can print $node->title anywhere you like in your node.tpl.php
There other ways to do this in a custom module which sound more efficient, but if this is a single minor task, i guess editing your tpls is a good solution
The $content array only is available in node.tpl.php, whereas in page.tpl.php you have a $page array with already rendered children.
I have a form and I want to see it in fiddler that what data is getting posted when form is submitted. I am not able to see anything. How do u debug in cakephp. I am a newbie in it
thanks
you must have Configure::write('debug',2); defined.
then you can use debug($data); to debug any data.
also in views or layouts you can have
<?php echo $this->element('sql_dump'); ?>
to output any database queries that had took place.
Inside app/config/core.php make sure the 'debug' value is 1 or 2 . t
If you use 1 warning and errors(if exists) will display
If you use 2 warning and errors(if exists) will display and all the sql query will display(that queries are runs on that page)
Within app/config/core.php make sure the 'debug' value is greater than 0.
For any value you would like to see, call the Cake 'pr' function to output it to the page. pr() will automatically expand any nested arrays and data structures.
you have to print data by using
echo "<pre>";
print_r($this->data);
echo "</pre>";
in this,Not required to 'debug' value is 1 or 2 .
I am using cakePHP v1.26.
In the default.ctp file,
I got a single of this code in it:
$session->flash();
I came a corss a web site in which the author suggested using this instead:
if($session->check('Message.flash')){
$session->flash();
}
I do not understand what this line of code is doing:
if($session->check('Message.flash')){...}
what is "Message.flash" in this case?
Is "Message.flash" a custom variable or
a built-in varibale which has been predefined in cakePHP?
Message.flash is the session variable name. It will be defined by cakephp, when you use $this->Session->setFlash('Your message'); from your controller.
if($session->check('Message.flash')){...} checks, if session Message.flash, which contains the flash message, exists.
Note also that contrary to the current manual description, $session->flash() does not echo the result, it just returns it, so you will need to have
echo $session->flash();
in your view.
For latest cakephp version
if(!($this->Session->check('Message.flash')));
// your code
In view section for show messages.
$this->Session->flash();