Drupal 7: best way to render arbitrary content directly into <body> while keeping what's in <head> - drupal

I'm new to Drupal. As I understand a Drupal(7 in my case) page normally would have layers of wrappers around a block, sections, regions etc ... What I'm trying to achieve is to render some arbitrary content directly into "body" with none of the wrapper overheads, while keeping everything in "head". I've researched hook_block_list_alter which allows you to exclude blocks before rendering - which doesn't offer the ability to customize (removing) sections. Then I came across hook_page_alter looks like a good way to go, although I haven't dug too deep yet, still trying to understand the structure of the $page object. I thought about other options such as using the context module to configure sections/zones when requested page url is in certain pattern.
What's "THE Drupal's way" of doing this?

I would suggest you to first try with Drupal's template system and then, if you can't achieve something try with hooks:
https://www.drupal.org/node/337173
So, as you mentioned drupal has layer templates wrapping one around another. Most outer one is html.tpl.php and if you want something to appear in page head put it there. Then, second inner one is page template, which can be different for any content (node) type. But you also have block templates, field templates...
To override templates for specific content type or field or something else Drupal has some special naming convention. So if you name you template some specific way (and clear the cache!) drupal will start use it in that specific case.
Check the documentation for more details.

Related

Drupal know from where things are showed

I have a strange question but I don't find any hint about that (if it's possible), for a drupal 7 website I have to modify some content of a page in the backoffice, but I really don't know from where some content of this page is created (a table, similar to a view table but not a view table).
I just want to know if there is any way to show which php function the page use to finally be showed. I know there is something like that for the theme (drupal theme debug) but I don't find something for my case.
Any idea ?
You need PHP profiler to check all functions called on page, there's a module for Drupal7 for XHProf integration. But I would suggest you to use your browsers inspector as mentioned by 2pha before. For example if there's a form on the page just use the form ID to find it. Custom classes are very useful in these cases, parts of the html codes etc. In your case search for table headers...
The code you are looking for is most probably in custom modules and the
general suggestion is to keep you custom modules in separated folder from contributed ones.

Create page of blocks only / Create a node of blocks

Sometimes I use a basic page as a place holder for the purpose of creating a node to hold blocks.
So I create a basic page and link it to a menu, then I use the blocks interface to configure certain blocks to display on that page only.
The problem with this approach is twofold. Firstly I don't need the page, but secondly when a user tries to edit the page they're understandably surprised to find nothing.
Is there a better way of creating a node of blocks? Ideally, the more lightweight the better..
Thanks,
Hmm, this solution requires installing another module, but also provides other great functionality such as revisions.
http://drupal.org/project/nodeblock
You would also have to convert all of your old blocks into these new "Node Blocks"
Another option would be
http://drupal.org/project/empty_page

Drupal - Show content on specific page

Am I able to add the following field to a content type, so that each piece of content I create can be conditioned to a page?
Or is there a module to extend Publishing Options, where by it adds all the pages I have created (just like 'Promote to Front Page')?
If not, why is no one doing this? As a new user to Drupal this seems like it would be a handy operation. (I have already tried this module but it doesn't achieve the results I'm after).
If none of these solutions are available, what would be the best alternative way of doing this?
I've posted this question on Stack Exchange for Drupal but I need a quick answer and there seems to be a bigger community here :D
You should use Context. With Context, you'll be able to manage contextual conditions and reactions for your drupal like Regions.
Have you used Views? it is one of the most common used drupal modules. It doesn't extend publishing options directly but it does replace it in a way. You can say by example put a list of al content-types: your_own_Content_type that have the publishing options of promoted to front-page. then sort them by title, date, what ever you like.
you could also create only one view and create multiple blocks out of it. you have to understand the logic of drupal: if you want different blocks on different pages, you have to create the different pages AND different blocks
create the view for one type of content-type and make one block out of it. put this block on the desired page. All your other blocks are made with the same view, just adjust a condition in your view and create a new block out of it. You should also put all your blocks in the same region, and set the to the right pages
here you can find a lot of documentation if you run into any problems... drupal.org/project/views
Views is the best at creating a slideshow of images or any type of data on your site.
Used in combination with nodequeue it might offer near or the full functionality you are trying to achieve (check this out ... and this too) - but I don't understand your question entirely.
By my opinion Views is too complicated task for much simple request.
There is a few ideas for solution:
Easy way - You can create a specific template file or add some if statments to the node.tpl.php(specific tpl better)
For minor changes - Create a new context with "path" filter and "theme html" reaction, than hide the field by the css
Best but complicated(large usages) - create a new "view mode" and implement the display by new "hook_menu".
~ Almog

Best practices to implement custom functionality on website

I was wondering if someone with Drupal experience could advice what are the best practices in the following situations. I think they are all common tasks for any website that you build.
Display a custom HTML of a certain content type at front-page (e.g., only the link and title).
Should I build a module only for this?
Customize the login form HMTL, including inputs, labels etc, to something very different from the default login block.
Again, another module?
Format the node view of some content types; for example: showing additional fields values. I have some Joomla experience and with it, it's very easy to override the template on your theme.
But with Drupal, it seems HTML is hard-coded on PHP files and there are very few thing that uses templates. Or am I missing something?
You should create a view (from Views module), and for this create display 'block'. This block you can use later on your site. Within your view settings you can choose what and how you will display.
It depends what you would like to put there. If you put just some static text, change theme could be a solution. But still, a bit smelly. What you should do, is to create a module use hook_form_FORM_ID_alter and add both - field to your form, and code to use values which user added.
Change templates for this content type in your custom theme; or use Panels module - here you have nice introduction; or use Display Suite module - which do pretty much the some work as creating a template
html is in php files, but where else can it go? Drupal also has it template overwrite system. The customization of the theme can be usually done using that alone.
As for your questions (there are also other alternative)
load the content type in view/block, display in list format on home page.
create your own theme for css changes. create custom tpl.php for
layout, and div naming etc.
same as above.
It doesn't hurt to create a new module, but generally it's not necessary unless you are going for something like a muti-step form.
You can use both Views & Panels in order to achieve what you've mentioned above.
For instance, Panels gives you the option to override the home page with your own content. This content can be organized with Views.
From drupal.org:
"The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented."
"The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout."

Fundamental understanding of how Views and Pathauto work together

I am having fundamental problems understanding when to use a pathauto rule, and when to use a views page path. I have several custom content types, and I am using blocks to display certain parts of nodes on certain paths. Then I use a views page to display the main node on a path.
When I do this, I can't use pathauto, as it overrides the paths I set in views. Eg.. If I set up a views page path of "location/%", and set a pathauto rule for Location content types of "location/[title-raw]", when I browse to mysite.com/location/mylocation pathauto wins, and simply displays the full node. And if I can't use pathauto, I can't add arguments on my blocks, because Drupal doesn't understand what it's looking at anymore! Arrrg!
I've tried installing Util, and altering the weight of the modules, but that didn't work. But I shouldn't have to do anything crazy like alter module weights, right? There must be some basic flaw in my thinking.
How do you keep your paths and content organized?
Help me flow like water, help me become the cup.
Ok, I've solved my problem. The actual question I should have asked was:
How do you display a single node?
I was basically using Views to style a single node. Of course, this is not what Views is designed for. See others with similar problems:
http://drupal.org/node/400400http://drupal.org/node/316907
My solution:
Let pathauto do all the work.
Add, arrange and style your content as desired at the theme
layer.
In more words: remove views page view, taking the corresponding location/% path with it. Set up your pathauto rules the way you want. Copy node.tpl.php to your theme directory. Duplicate that file and rename it node-[type].tpl.php. Alter node-[type].tpl.php instead of setting up rules in Views.
For more help theming a specific CCK content type see:
http://drupal.org/node/266817
Don't forget!
When using phptemplate node-[type].tpl.php suggestions, there must also be an original node.tpl.php template present in your theme directory or the template suggestion is ignored.
Hope that helps someone else!
Right. The % is a views argument, views superceeds URL aliasing every time. Drupal expects anything after location/ to be the passed in value you are looking for which is why it doesn't understand, or you aren't getting the result you want.
Why are you using views though to control a node view? If you are adding blocks to a view, you should be able to assemble the data in views, and use the Block admin to set the path it displays on (location*).
In general is a good practice to theme the node page and do not let views generate additional urls. It can lead to several problems, as many modules link to the standard node page. Use views to generate listings that links to the node page.
You can also theme a node page without coding, using context or display suite modules.
Just let pathauto do the work, a good idea is to generate the alias based on the menu hierarchy, to have a consistent url scheme. Check out this question: Drupal 7:Pathauto patterns from menu structure hierarchy

Resources