0

I'm a Java programmer trying to get started with Drupal. Specifically, I want to be able to create custom pages. More specifically, I want to understand the nuts and bolts of how this is done (I'm an engineer; it's just my nature) I have a little PHP experience and I've configured Drupal installations for years. I'm aware of many of the modules that help make this process easier (such as the Views module), but again--I'm interested in working through the nuts and bolts myself.

I'm not specifically interested in creating new Drupal modules, unless that is the only way to create new pages in Drupal. My primary interest is in being able to create a custom page. Let me give a few examples:

  1. I have a db of funny quotes. I'd like to be able to use Drupal to display a selected quote AND HAVE COMPLETE CONTROL OVER THE PAGE LAYOUT (and again--not using an existing module; I want to understand the inner workings). Don't ask why I'd want to use Drupal for this, or suggest alternate methods of accomplishing it. It's a made up example to illustrate what I'm wanting to learn. :-)
  2. This is a less made up example. I'd like to create a "newsletter" where the site editors can select submitted content and customize layout (all in a custom UI) and then create a page with that content, one suitable for either viewing in a browser or printing. Sort of a "desktop publishing" concept for Drupal. Again, don't suggest ways of accomplishing this. It's an example to illustrate what I'm wanting to learn.

Basically, I like Drupal's permissioning, modularity, and content management but I'd like to learn how to control display (as complete control over display as possible). The problem is that I don't even know what topics to start learning. Creating modules? Themeing? Something else? What is the mechanism or system that I need to learn to be able to completely control how Drupal pages are rendered?

Corollary question: does such control (not limited to just a block or region, but including menus, headers, footers, and everything visible on the page) require modifying the Drupal code directly or can it all be done in the theme/module systems?

1

Aaron is right that you'd likely want to handle much of this at the theme layer. You'd want to familiarize yourself with how drupal handles templates.

As for the actual creation of a page in code, this page does a pretty good outline of a method. I've not done this myself, but it reads correctly.

You'll first want to understand how to build a module. The basics are, you need a mymodule folder, and a mymodule.module file and mymodule.info file. Anywhere you see a resource that says to use hook_some_function, you're going to replace hook with mymodule.

The nuts and bolts of the page above outline:

-- Implementing of hook_menu (in this instance, the module's name is starting_drupal_dev)

/**
* Implements hook_menu().
*/
function starting_drupal_dev_menu() {
  $items['starting_drupal_dev/custom'] = array(
    'title' => 'Custom page',
    'page callback' => 'starting_drupal_dev_custom',
    'access arguments' => array('access content'),
  );

  return $items;
}

-- Using the custom function starting_drupal_dev_custom to define how the page renders

/**
* Custom callback function.
*/
function starting_drupal_dev_custom() {
  $content['raw_markup'] = array(
    '#type' => 'markup',
    '#markup' => '<p>Hello world</p>',
  );

  return $content;
}

You could then assign your various database queries to variables in order to render them within #markup.

Again, I've not used this particular method myself, but it seems to me that you could at least use this as a starting point for what you're trying to do. Not sure whether or not you could combine this method with theme templates for layout or not. Maybe somebody else could chime in with regard to that.

As for your final question, NEVER (usually) HACK CORE. Handle everything in modules and themes.

  • I appreciate the link, but even the screenshot on the page shows the content appearing on a page created by Drupal. It has the headers, menus, and the layout rendered by the system. I'm wanting to render a page--not a block or region or any sub-element of a page. I want to use Drupal's permissioning, modules, management systems, but I want to control EVERYTHING that's displayed. – Allen Apr 15 '16 at 0:55
  • That's simply a misunderstanding of how developing with Drupal works. The reason everything else on the page is rendered is because that is simply how they have their environment set up. They have a theme which is set to render regions, and blocks are assigned to them. You'd want to create your own theme, and I suppose define a single region for content. This markup would then be rendered within said region. I think that you are simply out of luck if you don't want to look into them development. Building a theme is exactly how you control the rendering of the overall page markup. – Mrweiner Apr 15 '16 at 1:15
  • 1
    To add to that, you can use your own modules to generate blocks/views with your own database queries by implementing things like hook_block_views and hook_block_info, as described at: drupal.stackexchange.com/questions/5582/…. You can also use hook_menu to build menus: drupal.stackexchange.com/questions/41570/…. In a really introductory sense, for your purposes, modules are for content/data and themes/theme templates are for presentation of that data. – Mrweiner Apr 15 '16 at 1:20
  • The sum total of these answers gives me a good starting point, I think. To clarify my previous comment: I meant I don't want to render JUST a block or region on a pre-defined form--I don't have some kind of prohibition on using blocks and regions, I just want more control over the UI than merely rearranging a limited palette of pre-defined elements. – Allen Apr 15 '16 at 3:10
  • So, to make sure I understand (because it seems I had a previous misconception): the themeing system is not limited to merely rearranging and reconfiguring existing elements like blocks and regions, but can also define them. So, if I want a page with a completely different structure, say no header/footer or menus for example, I can create a theme to do that? – Allen Apr 15 '16 at 3:10
0

control over the layout is intended to be accomplished through the theme layer, so you'll want to learn theming to control display. Drupal.org provides a good starting place for learning theming (https://www.drupal.org/documentation/theme), though other resources may be found through learning services like https://drupalize.me.

This is a question with a very lengthy answer and the best thing I can do is point you towards the right resources. Best of luck and welcome to the Drupal community!

  • To be clear: the vast majority of the themeing resources that appear at the top of search results center around more of what I'd call "configuration". Changing colors, configuring blocks, specifying which menus should show and where--in essence configuring the elements of an existing layout. But does the themeing interface allow me to create an entire page from scratch? – Allen Apr 13 '16 at 20:39
  • Yes, though that is an unusual avenue to theming. You can either dig deeper into the core theming api and override page.tpl.php templates, or you could explore the Panels module family. Panels Everywhere in particular is something that you'll likely find useful. – Aaron Silber Apr 13 '16 at 20:50
  • I literally don't have enough characters on Stack Exchange to explain how to do this. The learning curve is STEEP (but worth it IMO). – Aaron Silber Apr 13 '16 at 20:50
  • I appreciate your comments, but I have a nagging feeling in the back of my head that we're speaking two different languages. I'm not asking about modules that I'd find useful... – Allen Apr 13 '16 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.