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.