2

I am theming a specific node type in Drupal 7. I have named my file node--mynodetypename.tpl.php. Everything is fine and I can override the default node template; the issue is that I want to do very slight changes to the regular node template, basically the way the DIVs are structured. I get into trouble trying to replicate the original layout. I have installed the Content Templates module, and I am getting the variable names from there. I am not using it because it has some bugs in the current version.

  1. How can I add the comments block to the end of my content type? I just want the ordinary comments engine placed in there, but it disappeared with my new layout. Contemplate does not provide the variable to make all that comments block appear.

  2. Is there a correct way to publish the URL of an image? Contemplate provides me with this $node->field_image['pt-br'][0]['filename'] for the raw image file, but then I have to manually fulfill all the folder structure; it also gives me this $node->field_image['pt-br'][0]['uri']. It presents the folder structure above the image file, more or less like public://images/folder1/folder2/filename.JPG.
    Is there some kind of function I should call that would build the entire image URL for me?

  3. I have created a piped list of countries as a select list. In my layout, I would like to show the name of the country, but the variable generated in contemplate $node->field_country['pt-br'][0]['value'] only holds the country code; I would like to get the name of the country.
    How can I do that?

1

1 Answer 1

2

Take a look at the default node.tpl.php. You'll notice that they render the content with render($content).

I've never used Contemplate, but if you install the devel module you can then use the dpm() function to take a look at the variables in detail. Try dpm($content), and you see all the content that you can render, or even use the hide function to remove content. For example, you can use hide($content['links]) prior to render($content) and the links will not be rendered; you can display comments with render($content['comments']);. Don't forget to print the value returned by render(), as render() returns the HTML markup used to render the element passed as argument to the function.

You can easily render the image field with render($content['your_image_field']).
If you are using the Countries module, then you can control what it is displayed in the content types display on admin/structure/types/manage/your-content-type/display, and simply render it like you do with the rest of your content.

1
  • Wow, thank you so much, I will rush to go there and implement all your hints! Commented Apr 5, 2011 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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