0

I am trying to print some specific fields on a vocabulary term page in order to lay the page the way I want. <?php print render($page['content']); ?> prints the entire content but I want to extract specific values like title, field_photo etc. so that I can put them where and the way I want!

Here is an example how I want this to work:

I am creating a movie database website where each movie has casting associated with it. Each casting (actor or actress) is a vocabulary term. When I click on a term it takes me to a page (example URL: http://localhost/moviedb/tags/kate-winslet) where movies associated with that actor/actress are listed. The list is coming fine but I want to customize the look-n-feel of this page.

I overrode page.tpl with page--vocabulary--tags.tpl.php. Also I created a template.php file and written this function inside:

function introduction_preprocess_page(&$vars) { $vars['temp_var'] = $vars['page']['content']; }

which is equivalent of using $page['content'] directly inside .tpl file. I also used

<pre><?php print var_export(get_defined_vars(),TRUE) ?></pre> to get a the nested structure of nodes array. Based on that I tried to access a specific field like <?php print render $temp_var['title'] ?>, nothing is showing up.

I am definitely doing something wrong, but don't know where to check and what to change! I have started learning Drupal just a few weeks back.

UPDATE

I also tried the following code but no luck yet.

function introduction_preprocess_page(&$variables) { if (arg(0) == 'node') { $variables['node_content'] =& $variables['page']['content']['system_main']['nodes'][arg(1)]; } }

INTRODUCTION is the name of my theme.

In .tpl file I tried to access title the following way:

if (isset($node_content) && $node_content['title']) { print render($node_content['title']); }

I have referred the following URLs:

https://www.drupal.org/node/2288941 and https://www.drupal.org/node/223430

Please help me understand what wrong I have done.

EDIT (27.05.2016)

I tried the solution but it did not work. By doing some trial and error I noticed that my node--film.tpl.php template is actually being used even on taxonomy page. In my application film is a content type I created and there is a field called "cast" which is eventually a vocabulary called "tags". I am putting names of actors by using this vocabulary when adding a "film" type content.

My intention was to show a list of films where an actor is associated when a tag (actor) is clicked. The functionality works OK but I don't understand why this page is also using node--film.tpl.php template file and not taxonomy-term.tpl.php. I copied taxonomy-term.tpl.php to my theme folder, took out the line which is rendering the content, cleared cached but nothing happened. But when I take out the same code snippet from my node--film.tpl.php file, the content disappears! Which confirms that node--film.tpl.php is the template being used!

I then renamed the file as taxonomy-term--vocabulary-tags.tpl.php just as a random test, but nothing changed either!

I am still unable to customize the look-n-feel and field display in my vocabulary page.

2
  • Sounds like you are spiraling... node--film.tpl.php is the template file for nodes of content type film, wherever they appear. But your question is becoming more difficult to answer, it seems less clear now than at first, sorry.
    – Duncanmoo
    Commented May 27, 2016 at 20:35
  • Ok. No problem. I wanted to explain the scenario exactly what I have and where I want to go from there. Sorry if that made things more difficult to understand. Thank you for putting your time on this. Commented May 28, 2016 at 13:25

1 Answer 1

0

There are a few things here:

Taxonomy term pages are not nodes, and on a taxonomy term page you are going to have the following args:

  • arg(0) ~ taxonomy
  • arg(1) ~ term
  • arg(2) ~ tid (taxonomy term ID)

To override term pages copy site_root/modules/taxonomy/taxonomy-term.tpl.php into your theme templates folder to override all taxonomy term pages. You will also find really helpful instructions in that template file.

2
  • I copied the file taxonomy-term.tpl.php and to check whether this file is being access, I removed the line <?php print render($content) ?>. But the content is still on the page after all caches are flushed. I have one page.tpl.php, one node.tpl.php, one node--fild.tpl.php (overridden), page--latest-releases.tpl.php, one template.php (I commented out the preprocess_page function for now and of course taxonomy-term-.tpl.php in my theme folder. What I am missing? Commented May 27, 2016 at 11:18
  • Hi, I have Edited my question, under EDIT (27.05.2016) heading. Please let me know what I am not doing right to accomplish my goal. Commented May 27, 2016 at 13:03

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.