I'm looking to move "Submitted By" info from node.tpl to page.tpl however when I add the following from node.tpl I get errors. Im assuming I dont have access to those variables, but would like to know how I can set up a pre-proccess to get it to display as it does in the node.tpl
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
You can either use a preprocess function in the template.php of your theme, as explained here:
https://drupal.stackexchange.com/questions/40222/how-can-i-print-node-authors-last-login-date-on-page-tpl-php
In your case it would look like this (tested on Drupal 7):
function yourtheme_preprocess_page(&$variables) {
$variables['author'] = "";
if (isset($variables['node']) && ($account = user_load($variables['node']->uid))) {
$variables['author'] = $account->name;
}
}
And then in your page.tpl.php use this:
Submitted by: <?php print $author; ?>
If you don’t want to touch any of your theme’s files, but you need to output the author’s name in another region as the node content, you could create a view (block display) containing the node author, and assign it to the region.
While normally done in node.tpl.php, if the page is a node view page, the $node variable is also available in page.tpl.php
You can then use something like:
if (isset($node)) {
// Check if display submitted variable is set for this node type
if (variable_get('node_submitted_'. $node->type, 0)) {
// Do stuff
}
}
An alternative approach would be adding the required logic instead to an implementation of
hook_preprocess_page
Bonus update: You can see the $node variable added to page.tpl.php in core template_preprocess_page
if ($node = menu_get_object()) {
$variables['node'] = $node;
}
In page.tpl.php:
<div class="submitted">
<?php echo format_date($node->created, 'custom','d.m.Y'); ?><br />
<?php echo 'by ' . $node->name; ?>
</div>
Related
Does OpenCart Version 2.3.0.2 have some methods to check in header or footer .tpl files that current page is product? Example if (is_product) { // do something }
You can try to check if your session has product. $this->session->data['product_id'] You can check it anywhere. You can write the product to the session... for example:
$this->session->data['product_id'] = /*your product_id*/;
And now you can retrieve this product anywhere.
No, But you can create it.
File:
catalog/controller/common/header.php
Find:
return $this->load->view('common/header', $data);
Add Before:
$data['is_product'] = isset($this->request->get['route']) && $this->request->get['route'] == 'product/product';
File:
catalog/view/theme/default/template/common/header.tpl
Add where you need:
<?php if (!empty($is_product)) { ?>
<p>This is the product page</p>
<?php } else { ?>
<p>This is not the product page</p>
<?php } ?>
I want to add a new field in virtuemart new product form, how can i do that ?
I add:
var $is_act = 1;
in "components\com_virtuemart\tables\products.php"
And
<?php echo VmHTML::checkbox('is_act', $this->product->is_act); ?>
And in database but what is appear is a checkbox without a string behind it, what is the wrong ?!
The VMHTL::checkbox function just create a check box without strings.
If you want to add string behind it you have to do something like this.
<?php echo JText::_('COM_VIRTUEMART_PRODUCT_IS_ACT') ?>
<?php echo VmHTML::checkbox('is_act', $this->product->is_act); ?>
And then COM_VIRTUEMART_PRODUCT_IS_ACT should be added inside language file too.
for more clearness just check VM default product_edit_information.php page inside
administrator/components/com_virtuemart/views/product/tmpl/
Hope its helps..
I've been trying to create simple script that swaps table data based on the active currency code. It's for a size chart (on product.tpl).
PREMISE:
IF "USD" is active then display table "A" (Inches), ELSE display table "B" (Centimeters).
I'm a total hack with php/js, but enough to find my way into trouble. :)
I followed this thread to bring the currency code variable into "product.tpl": How to get currency to show on product page in opencart?
Now I'm just banging my head, I can't find the right variable to create the swap... I've tried multiple variations of a simple If/Else script, basically like this:
<?php if ($currency['code'] == $currency_code) { ?>
<td>15.5"</td>
<td>25"</td>
<?php } else { ?>
<td >40cm</td>
<td >64cm</td>
<?php } ?>
Anyone have a clue what the script might look like?
Or am I totally barking at the wrong cat here?? Thx
Just use the session value for the currency code...
<?php if($this->session->data['currency'] == 'USD') : ?>
<td>15.5"</td>
<td>25"</td>
<?php else: ?>
<td>40cm</td>
<td>60cm</td>
<?php endif; ?>
In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!
<?php if($node->type == 'blog'): ?>
<div class="blog-page">
<div class="title-post">
<div class="top-image">
<?php print $node->field_image[0]['view'] ?>
</div><!--TOP-IMAGE-->
<p>Posted on ?php $row['created'] ?>, by
<?php print $row['name'] ?></p>
</div>
<div class="content-page">
<?php print $node->content['body']['#value'] ?>
</div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>
Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.
echo '<pre>';
print_r($node);
echo '</pre>';
lets say it outputted something like this for simplicity's sake:
stdClass {
nid = 3
content = stdClass {
raw = " ... "
clean = " ... "
}
}
To output those bits of information in your template, you'd write in the following way.
for a field with no subclass:
<?php print $node->nid ?>
for a field with a subclass:
<?php print $node->content['raw'] ?>
Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.
so, if you wanted to construct a url, you'd just chain it up:
<?php
$nid = $node->nid;
$uri = "some/path".$nid;
print $uri;
?>
I have an app where I need to call some JS in the onLoad event of the BODY tag of two forms. However, I can't find how to modify the tag for just them. Does anyone know?
Frank
inkedmn certainly has provided the right answer for this case, but in general, you can "hand information up" like this:
(in views/controller/view.ctp)
$this->set('bodyAttr', 'onload="something"');
(in views/layouts/default.ctp)
<?php
if (isset($bodyAttr)) {
$bodyAttr = " $bodyAttr";
} else {
$bodyAttr = null;
}
?>
<body<?php echo $bodyAttr; ?>>
I often use it like this to add extra classes to a "top level element":
<?php
if (!isset($docClass)) {
$docClass = null;
}
?>
<div id="doc" class="<?php echo $docClass; ?>">
You don't need to modify the body tag to have Javascript execute when the page loads. You could just include something like this in your layout where appropriate:
(jQuery)
$("body").load(
function(){
// do stuff when the body element is loaded.
}
);
Or, if you want to have the code execute when the document.ready event fires:
$(function(){
// do stuff when the document is ready
}
);
Or, if you don't want to use jQuery, you could do something like this:
function doStuff(){
// whatever you want to happen when the load completes
}
window.onload = dostuff;
Good luck - and please clarify your question if this answer isn't satisfactory.
I do the following:
We apply $ bodyLoad in my body
<body <? = (isset ($ bodyLoad)? 'onload = \''. $ bodyLoad.' \'',''); ?> >
Already in my [action]. Ctp, I do the following:
<? php $ this-> set ('bodyLoad', 'field.focus ();');?>
If you want you can also put this code in the controller.
Good luck