1

i want make a photo gallery with drupal and i need to:

  1. a download button for current node picture

  2. an embed code that allow visitor to use photo on other Websites. like this: enter image description here

i have some experience with Drupal and reading PHP codes, but no experience with writing PHP codes. i tried to make a block in bottom of node picture with PHP filter and following content:

<pre><a href="<?php t('[node:url]'); ?>" title="<?php t('[node:title]'); ?>"><img src="<?php t('[node:field_image]'); ?>"></a></pre>

this code not work. please help me.

many thanks :)

1 Answer 1

2

To translate the tokens in their values, you can use:

token_replace

e.g:

$nid = token_replace('[node:nid]', array('node' => $node));

You need to be able to pass the required parameters for that token, e.g $node for node tokens.

3
  • using: <?php $nid = token_replace('[node:nid]', array('node' => $node)); echo $nid; ?> gives error: Notice: Undefined variable: node in eval() (line 2 of /srv/http/g/modules/php/php.module(80) : eval()'d code).
    – Ma3x
    Nov 24, 2013 at 10:49
  • As mentioned, you'll need to get the $node object first. That depends on the code context. Sometimes, if on a node page, it's $node = menu_get_object('node'); Nov 24, 2013 at 21:04
  • as i said i have not experience to write PHP codes, and thanks to show me the way directly. i used this and worked: <a href="<?php $node = menu_get_object('node'); $url = token_replace('[node:url]', array('node' => $node)); echo $url; ?>" title="<?php $node = menu_get_object('node'); $title = token_replace('[node:title]', array('node' => $node)); echo $title; ?>"><img src="<?php $node = menu_get_object('node'); $field_image = token_replace('[node:field_image]', array('node' => $node)); echo $field_image; ?>"></a> thanks man :)
    – Ma3x
    Nov 24, 2013 at 21:33

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.