1

I create a subtheme base on bartik theme.

Then I create a panel, and put the user login block to the panel.

I want to change some text in the default user login from.

I find the theme suggestion about how to override block: block--[region|[module|--delta]].tpl.php

So I try to create block--user--login.tpl.php, And try to type whatever word to this file:

111

when I visit the login form, still default, not changed.

I try to clear cache, can not work too.

EDIT:

I paste the follow picture for better explain.

  • the 111 is a login form block in page, the right form is a login form block in a panel.

enter image description here

  • this is my block--user--login.tpl.php file

enter image description here

2

This sounds like a job for hook_form_alter() and it can be used from either a custom module (eg, MODULENAME_form_alter()) or in this case probably more easily from your theme, eg, something along these lines inside your template.php file:

function THEMENAME_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {

    case 'user_login_block':

      // drupal_set_message('<pre>' . print_r($form, TRUE) . '</pre>');  // uncomment to see what you have to work with

      $form['name']['#title']='Enter UserID here'; // originally "Username or e-mail"
      $form['pass']['#title']='Enter Secret here'; // originally "Password"

      break;

    // other form ids go here

  }

}

The above (after clearing caches) will turn this:

enter image description here

into this:

enter image description here

If you need to change other text in the form, you can uncomment the drupal_set_message() and look in the form to see what you have to work with and change it appropriately.

ADDITION:

If you want to get rid of both of the links, eg, the Create new account and Request new password you can either do:

unset($form['links']);

or set the access to them to FALSE, eg:

$form['links']['#access']=FALSE;

Lots more information about this can be found in the Drupal Form API Reference. I would look into the #weight key for changing the position/ordering of elements in the form.

  • Thanks, It seems a nice solution, But I wondering why that can not override the block template file when block into panel? – TangMonk Mar 29 '14 at 14:32
  • The block template is a wrapper for whatever goes in it, eg, the html <div>s and such and then $content in there would contain the output of the form above. Since it isn't a render array (1/2 grrr), you'd be hard pressed to alter it as easily as above. – Jimajamma Mar 29 '14 at 14:37
  • thanks, one more question: How can I change the default element location or delete some element? ( e.g.: remove the create new account and request new password) – TangMonk Mar 29 '14 at 14:40
  • added to the answer – Jimajamma Mar 29 '14 at 14:48
  • thanks, it solved my problem. But when if a block not contain form, so the $form variable can not be work. – TangMonk Mar 29 '14 at 15:13
0

Edit your panel and make sure you are in content. Now you will notice very block has a small gear icon on its right. click on the gear icon and then select css properties. Under div class put the name you want. For example loginblock

then go to your subtheme .css file and add the div there and make the changes you need.

For example:

.loginblock { color: red; } 

PS: I suggest you watch part 1,2,3 of this series Drupal 7 Panels Module Basics it has great info on panels, that's is how I learned.

  • thanks for your reply, I just want change(add or delete) some text in the login form instead of change style. – TangMonk Mar 29 '14 at 12:28
-1

is this what you want to do?

enter image description here

then you need to go to your website then right mouse click and then click view source. then search for user-login-form you need to copy all the code where the form starts and ends onto the block--user--login.tpl.php file

for example block--user--login.tpl.php contains:

<form method="post" id="user-login-form" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-name">
  <label for="edit-name">I just edited this, woo<span class="form-required" title="This field is required.">*</span></label>
 <input type="text" id="edit-name" name="name" value="" size="15" maxlength="60" class="form-text required" />
</div>
<div class="form-item form-type-password form-item-pass">
  <label for="edit-pass">Password <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" id="edit-pass" name="pass" size="15" maxlength="128" class="form-text required" />
</div>
<div class="item-list"><ul><li class="first"><a href="/user/register" title="Create a new user account.">Create new account</a></li>
<li class="last"><a href="/user/password" title="Request new password via e-mail.">Request new password</a></li>
</ul></div><input type="hidden" name="form_build_id" value="form-_elpq-7B19Scnbgk13TZtp9YWCcANc-rDYCWcHPuihI" />
<input type="hidden" name="form_id" value="user_login_block" />
<div class="form-actions form-wrapper" id="edit-actions"><input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" /></div></div></form>  </div>
</div>
  </div>

Pros: You don't need to know PHP nor how to create a custom module. (The noobie approach).

Con: If you change theme's you will need to make a copy of this template and put it in your new theme's template folder.

Counter the con: There might be some other (views, blocks, nodes?) templates that also need to be moved if you change themes, since this is in the /sites/all/themes/yourtheme/templates folder, you will likely not forget to move it with the others? Therefore, this approach is not as bad as people may think.

Don't get me wrong, the accepted answer is the better approach, if you have the knowledge that is.

  • Looking at the "wow" (in the screenprint, and the TPL file, this obviously ALSO works. But what are the typical cases where you'd using "this" technique instead of the hook_form_alter() approach (as in the accepted answers)? And/or what are the pros and/or cons of this one? 1 I can think of already is "if you change themes, don't forget to redo this (which is not needed if you use hook_form_alter(), right? – Pierre.Vriens Jul 5 '16 at 7:05
  • @Pierre.Vriens I was a noob back then :P – No Sssweat Jul 5 '16 at 7:07
  • Not anymore ??????? Anyway, If I was in your shoes, I'd "copy" this answer in your other answer, as an annex or so, with something like "this is another approach to get a similar result, typically used by noobs. I wouldn't recommend it anymore because so and so ... And after the copy, I'd delete this answer (to avoid comments like my prior one). Of course: your call ... – Pierre.Vriens Jul 5 '16 at 7:12
  • @Pierre.Vriens checkout my edit – No Sssweat Jul 5 '16 at 7:23
  • 1
    Voilà, learning from mistakes, the best possible training IMO ... Moreover, it could also be considered as a "make it right before you make it better" approach (right = this answer; better = accepted answer). And a variation of your "pro": "you don't need a budget to hire somebody who knows PHP or custom modules stuff ... – Pierre.Vriens Jul 5 '16 at 7:30

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.