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.
Im trying to convert over to Groups from Organic Groups and running into an issue with nodes vs entities. Currently, I cant find a way to access the custom fields for images I added to group types. Has anyone come up with an easy way to insert custom image field output to page.tpl.php?
Comments
Comment #2
pribeh CreditAttribution: pribeh commentedHi @trickfoxx, I'm trying to figure this out right now. It looks like I can't get any values from page.tpl for groups unlike other entities. I'm going to continue to hammer this out. Let me know if you've found out anything.
Comment #3
pribeh CreditAttribution: pribeh commentedHere's what I'm trying:
But it isn't working.
Comment #4
isaachorton CreditAttribution: isaachorton commentedOk, pribeh, here is what Ive worked out for this:
fields wont work in the page templates as far as I can tell none of the usual methods work, but they do in the group.tpl.php template. so in my case I just reworked the page--group.tpl.php template to have less of the html markup and moved what I needed into the group.tpl.php. Took a little but it worked once complete.
However I still feel like its the wrong way to do it. Id really like to see a preprocess function that passes the $group variables into the page templates but since im a designer, its hard for me to work out how to accomplish that.
Something like this should be able to work on a page.tpl.php template imho.
$fieldImage = field_get_items('group', $group, 'field_image');
Comment #5
pribeh CreditAttribution: pribeh commented@trickfoxx That's what I was doing. I'll go back to that for now. I honestly can't figure out why we can't access field data from the page level.
Comment #6
flocondetoile@pribeh The reason is the design of the Drupal system theme. Page templates are responsible to render regions, and so blocks inside regions. Content templates (node, group, etc.) are responsible to render field attached to these entities. If you want to access field from the page template you could use Display Suite, or field as block module which permit you to expose field (or DS regions for Display suite) as a block, and you can then place them in any regions you need. Otherwise, you can too implement a preprocess function on page template which can provide the fields you need as variables in the page template.
Comment #7
isaachorton CreditAttribution: isaachorton commentedAn example preprocess function would really help us out! Im just trying to figure out how to get the variables into the page templates on a field by field basis. Theres many examples of why you would need a field outside of the node template. A common design feature is to have a featured image as a background or header and the title of the page needs to be BELOW the featured image. Since the title is displayed in the page template, it needs to be rendered there so that it can be above it in code and display.
There is some documentation although very limited discussing this scenario and why its needed. Its just a little trickier doing it with a "group" type of entity vs a node. For that, the documentation is non-existent. trying to put all the markup in the group.tpl.php template creates other problems with page display since the action_links and other page variables are not available on the group template. This makes the "view/edit/delete" links have to be moved into some alternative location, bad for usability....
Its crazy how frustrating it is for a designer to not understand how to get these variables into the page templates when you know the field is right there!
Comment #8
Soul88We thank everyone for their collaboration on this issue, but as the D7 version is no longer supported, we will now close all D7 issues to keep the issue queue a bit tidier. This information won't go anywhere, it just won't show up on the list of open issues anymore.
Please see: https://www.drupal.org/project/group/issues/3163655 and https://www.drupal.org/project/group/issues/3203863#comment-14100281 for more details.