I have created an Article in Drupal 7 and I want to customize how the content is displayed.
I am trying to modify the node.tpl.php, which gives you access to the $content variable, but this is a multidimensional array and I cannot extract the keys or values within it.
Is there a way of seeing inside $content to find out the exact value pairs that I need?
Or is there another way of customizing the display and output of Drupal 7 content?
If you install the and enable the devel module, it gives you access to a very handy function dsm that will render a widget that lets you explore the contents of any variable or object. So in your node.tpl.php file: dsm($content); at the top will let you inspect the content. Usually you will want to create a custom node-type.tpl.php file e.g. node-article.tpl.php which is only applied to nodes of a certain type.
Related
I would like to extract dimensions length, width and height from a single value 51x51x21cm into 3 separate fields using PHP in the Wordpress plugin WPAllimport.
Any idea how to solve this?
Thanks!
Menno
I use WP All Import frequently and it sounds like you will need to do one of the following:
Reformat your data in a spreadsheet software (i.e Microsoft Excel)
Using WP All Imports custom function editor, create a custom PHP function to split the data into 3 separate values and use their inline PHP syntax to output each value accordingly
If you have experience with PHP, the custom function editor mentioned above should be at the bottom of the "Edit Import" page when creating or editing an import. You can find more about the custom function editor here.
I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.
I am not experience, can smbd show the way. I need give possibility to simple user to create Page and he need to have possibility in select area choose Templates type for the page which he is create. How to do it?
I suggest you create multiple Content Types and give them the names of the templates you want to offer.
Then, you'll need to create those templates, you should probably use node.tpl.php as a base.
After you're done with a template you can save it in the templates folder (/sites/all/themes/[THEME_NAME]/templates/) and name it like node--mycontenttype.tpl.php
Note that you'll need two dashes (--) after the word node in the filename. For more information on designing templates for Drupal, please refer to https://www.drupal.org/documentation/theme
How do I control the output of a node rendered inside a specific region?
Inside Sidebar First, I can theme blocks by creating a block--sidebar-first.tpl.php template file. However, creating a node--sidebar-first.tpl.php does not work.
Unfortunately, Drupal doesn't have support to have node template based on region. You can check out this link.
If you want to achieve your goal you can use Display Suite module. Here are some screen-casts about how to control your content with Display Suite. Here's also a comment about this.
For theming a node first thing you need a custom node template file.
Inorder to do that copy your node.tpl.php and rename it as node-[ur_node_name].tpl.php .
Now you have created a custom node template. In case of blog entry my node name would be node-blog.tpl.php [Drupal-6] and it would be node--blog.tpl.php [Drupal-7].
NOTE:
Make sure the [ur_node_name] part is the machine readable name.Now in your new node template give your corresponding styles and print the contents of the node.This is how you theme a node.Hope this helps you... :)
When I create a content type, I want to show all the posts of this content type on a page, I have to use view module. I don't like that.
Can I just specify the page and url when I create the content type?
But there is only one option, only front page. Can I change that? Hope you guys can tell me.
The views module is one of Drupal's killer features, you might want to reconsider writing it off completely.
Anyways, if you want to display all nodes of a type, you will have to code this yourself in a custom module. This means you will have to write some SQL, load the nodes and render them in a list. In this example you could use the EntityFieldQuery class to construct the query instead of writing the SQL yourself.
The end result will not be much different than what views will do for you, only difference is that you will need to create all of this with code in a module, instead of just setting this up in the Views UI.
I agree that views is a powerful tool that you shouldn't count out, but if you're set against using it (i refuse to use it on 2 of my sites purely due to overhead), You could use taxonomy instead. The taxonomy module already has a views style list for each term, I used this to achieve something similar to what you're looking for:
Set up a vocabulary whose terms match your node types and note the vid
add a hook_node_insert into your module file:
mymodulename_node_insert($node){
$terms=taxonomy_get_tree($my_vid); //where $my_vid == the vid of your vocabulary.
foreach($terms as $term){
if(strtolower($node->type)==strtolower($term->name)){
$items=array((array)$term);
$field['storage']['type']='field_sql_storage';
taxonomy_field_insert('node', $node, $field, null, null, $items);
}
}
}
After that you just need to add menu links pointing to your taxonomy page. Just as a note, I render all of my lists that I don't use views for with my own custom functions so I'm not sure what limitations this method might present.