0

I'm trying to display the taxonomy term (filter (Better Exposed Filters) on Views) as an image. I added an image field, upload an image (marker). Create template views-view-field--maps--field-type.tpl.php. I found example how to make theming of taxonomy-term here: http://www.milesjcarter.co.uk/blog/web-design-development/drupal-views-templating-tutorial-outputting-respective-image-fields-multiple-taxonomy-term-references

My code looks like:

if(isset($row->field_field_type)) {
    $term = $row->field_field_type;
    foreach($term as $type){
        render(field_view_field('taxonomy_term', $type['raw']['taxonomy_term'], 'field_marker', array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));
    }
}

For some reason, the code does not replace taxonomy term, it just show me messages:

Notice: Only variables should be passed by reference in include() (line 8

What could be the reason? I would be grateful for any advice.

I try dpm:

dpm(render(field_view_field('taxonomy_term', $type['raw']['taxonomy_term'], 'field_marker', array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail')))));

And it show me this:

<div class="field field-name-field-marker field-type-image field-label-hidden"><div class="field-items"><div class="field-item even"><img typeof="foaf:Image" class="img-responsive" src="http://localhost/sites/default/files/styles/thumbnail/public/1.png?itok=A6-EJb27" width="63" height="100" alt="" /></div></div></div>

I know that there is a module Taxonomy Image I tried to install it, but after activation necessary functionality was not added to my site.

0

There are multiple ways to do it. The easiest way would be to use views. You can create a view of taxonomy terms with only an image field and display it as a view block.

See an example of view below.

Views Views Result

Let me know if you need any help.

  • thanks for the answer. I use the taxonomy term for filtering (Better Exposed Filters) as checkboxes. Is it possible in this case to use the solution you have proposed? – makbuk Mar 10 '17 at 7:43
0

I've got solution. Thanks xandeadx for the help

function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
    foreach ($form['TAXONOMY_ELEMENT']['#options'] as $tid => &$name) {
        $term = taxonomy_term_load($tid);
        $name = '<img src="' . file_create_url($term->FIELD_IMAGE['und'][0]['uri']) . '" />';
    }
}

TAXONOMY_ELEMENT = tid_1

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.