简体   繁体   English

Drupal 7制作图像链接。 不会显示图片?

[英]Drupal 7 making image link. wont show image?

I'm trying to make an image link but my image file wont show can anyone help? 我正在尝试建立图像链接,但是我的图像文件不会显示任何人可以帮助? Thanks 谢谢

Here's my code 这是我的代码

function linking_module_basic(){
    $content = array();

    $variables = array(
    'path' => 'sites\all\modules\tshirt.png',
    'alt' => t('Click to create new shirt'),
    'title' => t('Create shirt'),
    );

    $content['themed_data'] = array(
        '#type' => 'markup',
        '#markup' => theme('image', $variables),
        '#prefix' => '<div class = "linking-module-image"><a href = "https://www.facebook.com/">',
        '#suffix' => '</div></a>',
        '#attached' => array(
            'css' => array(
                drupal_get_path('module', 'linking_module') . '/linking_module.css',
            ),
        ),
    );

    return $content;
}

Here's my hook_menu 这是我的hook_menu

      function linking_module_menu() {

        $items = array();

        $items['linking'] = array(
        'title' => 'A Linking module',
        'page callback'  => 'linking_module_basic',
        'access arguments' => array('access content'),


    );
    return $items;

  }

I cant seem to figure this out. 我似乎无法弄清楚。

Here is your problem!!. 这是你的问题! Drupal was encoding the image path!! Drupal正在编码图像路径!

On your path value for image, change the back slash to forward slash and also add the base path. 在图像的path值上,将反斜杠更改为正斜杠,并添加基本路径。

function linking_module_basic(){
    $content = array();

    $variables = array(
    'path' => base_path() . 'sites/all/modules/tshirt.png',
    'alt' => t('Click to create new shirt'),
    'title' => t('Create shirt'),
    );

    $content['themed_data'] = array(
        '#type' => 'markup',
        '#markup' => theme('image', $variables),
        '#prefix' => '<div class = "linking-module-image"><a href = "https://www.facebook.com/">',
        '#suffix' => '</div></a>',
        '#attached' => array(
            'css' => array(
                drupal_get_path('module', 'linking_module') . '/linking_module.css',
            ),
        ),
    );

    return $content;
}

It should work now as long as you have the image in the specified path!!. 只要您在指定路径中有图像,它就应该可以正常工作!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM