1

I've created a content type with some fields like link , address. And I did content-type node theming with name node--machine-name.tpl.php and all fields are printed by this code

<?php print render($content['content']); ?> 

or individual fields like this

<?php print render($content['field_link_url']); ?> 
<?php print render($content['body']); ?> 

But I want to save the link field in a variable, which will be used in various ways.

I just want this field_link_url field to not be printed but to be stored in a variable

What I Tried

  1. echo $link = $field_link_url['und'][0]['value'];
  2. echo $link = $content['field_link_url']['und'][0]['value'];

Apart from that I got the message with all the array fields with this

`drupal_set_message("<pre>". print_r($node,true) . "</pre>");`

which gave me this..

stdClass Object
(
[vid] => 51
[uid] => 1
[title] => Run Tests on the Cloud. No Software or Hardware Required!
[log] => 
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[nid] => 51
[type] => landing_pages
[language] => und
[created] => 1392994690
[changed] => 1393072611
[tnid] => 0
[translate] => 0
[revision_timestamp] => 1393072611
[revision_uid] => 1
[body] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [value] => 
                            No software or hardware to buy or maintain. 
                        [summary] => 
                        [format] => full_html
                        [safe_value] => 
                            No software or hardware to buy or maintain.


                        [safe_summary] => 
                    )

            )

    )


[field_link_title] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [value] => START A FREE TRAIL
                        [format] => 
                        [safe_value] => START A FREE TRAIL
                    )

            )

    )

[field_link_url] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [value] => http://xyz.displaybox.in/why-xyz/easy-to-manage-your-tests
                        [format] => 
                        [safe_value] =>  http://xyz.displaybox.in/why-xyz/easy-to-manage-your-tests
                    )

            )

    )
0

On template file node--machine-name.tpl.php $node is an object. So you can access its value like $node->nid as node id. So if you want to access field_link_url field value directly then use following code . $link = $node->field_link_url['und'][0]['value']

| improve this answer | |
0

echo $link = $content['field_link_url']['und'][0]['value'];

This way must be correct! Check *field_link_url* key in content variable with dsm or kpr fucntion.

And try to get *field_link_url* value from this key.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy