Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lsolesen on
I have created a content type to use for e.g. http://vih.dk/fag/fodbold. I have a title, description and a picture. I want to access the picture in an exact size in my page.tpl.php, as it has to be printed out in the css for the design to be solid. How do I access the individual fields and exactly the correct picture size in page.tpl.php?
Comments
<?php echo
echo render($content['field_name']);
You could use the image styles thing to get images resized on upload.
works at bekandloz | plays at technonaturalist
$content is NULL
That did not work for me. I tried:
But that did not work for me on Drupal 7?
I'm an idiot. I just noticed
I'm an idiot. I just noticed you said page.tpl.php. It needs to go in node.tpl.php or node--type.tpl.php. Sorry.
works at bekandloz | plays at technonaturalist
Rearrange my templates
Maybe I need to rearrange my templates a bit? http://github.com/vih/vih.dk-theme
-=[o]=-
Do you have a html.tpl.php kicking around in there somewhere where I can't see it?
I don't know if you've found Lin Clark's Grok Drupal 7 theming notes in your travels but I found it really useful getting my head around the structure of how to set the different templates up.
api.drupal.org is really helpful:
And of course you need the .info file.
Clear your caches every time you add a .tpl.php file or modify the .info file otherwise it might not pick up.
Sorry if this is all repeat stuff for you :) If you want working examples (not sure how good they are but it appears to work) I can show you the templates for technonaturalist. It's my personal site/experiment/testbed/attempt-to-help-test-D7-and-whatever-modules-I'm-using running D7b2.
works at bekandloz | plays at technonaturalist
the same
agree with you
Have you found a nice way of
Have you found a nice way of rendering field in page.tpl.php?
There is a solution: http://stackoverflow.com/questions/4662416/drupal-7-how-to-print-node-ta... But say in d6 you hadn't do any preprocess in template.php.
Cheers,
Andrey
Free and Premium Drupal Themes | Drupal Sites Showcase. Add yours! | My Blog
I've found a nice way that works for me.
The fields are available deeply nested in the $page variable, so I use a simple preprocess function for easier access:
Then I can simply render fields like this in the page.tpl.php:
Don't forget to hide() the field in the node.tpl.php, else it will be printed twice.
Thank you
Found this through a search, it worked perfectly, thanks a million!
Is the preprocess function placed in template.php?
I put the preprocess function in template.php and the second snippet in page.tpl.php. I updated the field to match my own. There are no errors showing but the field still isn't displayed.
Ultimately, I'm trying to print a field before the node title and this seems like the way to go. Do you have any advice?
Are you sure the preprocess
Are you sure the preprocess function is named correctly for your theme/module and is actually called?
Just little bit more safe in
Just little bit more safe in case something go wrong before.
https://interface-network.com - Interface Network is an action and research technology governance agency.
Use this:
If your field is 'field_something', then in template.php:
in page.tpl.php:
in node.tpl.php:
hide($content['field_something']);
Hide code: <?php
Hide code:
hide($content['field_name']);
try this:<?phpif(
try this:
What you were looking for . . .
The following will give you a renderable array so that you can output it in your page.tpl with the image style(picture size) and link if required:
For single image:
For multiple images:
Then you can:
To take it a step further, you can do a little something in your template.php file to keep the logic out of page.tpl
So finally, you can easily print your field in page.tpl.php;
more about field_view_field
Hope that helps someone.
My image is showing but I am
My image is showing but I am getting this error randomly (refresh the page it goes away, do it a few more times, it does it again:
any idea why?
Try this..works
Try this..works perfect
render single field in module or template file
hi,
I was facing some problem while loading single field in my module file, so I have got it right by this...
Note: It was a opening Hours module field. But it will work for any field.
Simple print render field in page.tpl.php
This worked great for me, in page.tpl.php:
<?php print render(field_view_field('node', $node, 'field_EXAMPLE)); ?>
HOWEVER: I expect much better from Drupal. Why is there not a handbook for getting these functions? I need the ability to get a field URL or any other native information in it. I have been endlessly frustrated by this type of thing since upgrading to Drupal 7.
I'm not printing variables in page.tpl.php just because I can. I need to theme page templates that are called by URL structure (another function that was confusing to upgrade), and functions like these make it possible.
This last is perect but to make rendering without label?
This last is perect but to make rendering without label?
<?phpprint
print render(field_view_field('node', $node, 'field_EXAMPLE', array('label'=>'hidden')));
See here for more options
F
Works Great!
This worked great for me, but I switched it up a bit for this
$image = field_view_field('node', $node, 'field_image', array('label'=>'hidden'));print render($image);
Gonzalo Garcia
Freelance Webmaster
Problem!
Your code works well... but give me an error on /user (login) page, this one:
Apologies - I was in the
Apologies - I was in the middle of figuring this out as well. I seem to have it sorted thanks to this article and this article (for figuring out printing image fields).
In my case, I was printing an image. This is slightly more complex, so I'll add it here in case anyone needs it
This is working for me and so far hasn't thrown up any errors. Let me know how you get on.
F
how to get first node content on view page
My query is to get the first node content on the pages generated through the pagination on the page which is created through view
great!
thank you so much for this answer -:)
This works great! Somebody
This works great! Somebody knows how to do this für multiple images in the same field??
Plz code for multiple images
Anyone knows how to edit this code in order to display all the fields of that custom content?!
I don't know why this is
I don't know why this is necessary. The following works fine for me and resolves the "Strict warning: only variables can be passed by reference" from the another comment:
This renders the image according to the configured "Full content" display settings and that's the best place to set things like image styles. In my case this is located at
Structure > My Content Type > Display Settings > Full Content
.Simple approach for page.tpl.php
A simple approach to output a field value in page.tpl.php:
(Use
<?print print_r($node); ?>
or, when using the devel module,<?php dsm($node); ?>
to figure out the cascading variables.Url field image
how can use to get url of a field_image?
This's work for me
place this in page.tpl.php
This is an unsafe way to
This is an unsafe way to output fields - see this article for the reasons.
See my earlier post for a safe way to print fields.
F
Thank You.
it worked.
Works fine :)
Works fine :)
Could you use menu_get_object()?
I'm honestly not sure if this is "proper", but it works!
Then add this to your page.tpl.php:
<?php if (isset($page_banner)) : print $page_banner; endif; ?>
WORKING FINE
Please refer this link
https://www.drupal.org/node/2288941#comment-11970823