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.
I am using the metatag module and there is no problem to retrieve fields of the very node displayed. However, I cannot find how can I use the field_product_image of the product entity to use as token for the Open Graph Protocol image attribute.
As I can use "regular" fields, I have added the issue here, and not in the metatag issue queue. Any help is blessed :)
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedNo clue, but I really don't think this is the right place for such a question. We don't handle support requests here (per the issue submission guidelines), and I've never heard of the module in question. : P
Comment #2
Amir Simantov CreditAttribution: Amir Simantov commentedDone: here. Also added a link to the metatag module which you've never heard of :P
Comment #3
rvallejo CreditAttribution: rvallejo commentedI posted an answer at drupalcommerce.org, but copying here for others stumbling on this issue:
How many products do you have on each node?
Field value deltas start at 0, which means if your display only has one product attached to it (or you have a single-value product reference field) then you should be using [node:field-product:0:field_product_image] instead of [node:field-product:1:field_product_image].
Poor UI, IMHO - it doesn't provide the 0th value in the available tokens dialog, but it works if you type it in.
For multiple-value image field metatags, there are a couple issues:
First, the Metatag module/submodules currently list all image urls in a comma-delineated list in a single meta tag. There is a fix for Open Graph tags at https://drupal.org/node/1305402#comment-6420040.
Second, selecting which image you want to use from a multiple-value field doesn't seem to be working currently. Same issue, later comment: https://drupal.org/node/1305402#comment-7890015
I'm also working on a sandbox module to expand the Metatag module to provide integration for Drupal Commerce/product-related tags, available at https://drupal.org/sandbox/rvallejo/2102725. I include the fix for splitting multiple images into multiple tags for Open Graph and Twitter, based on code at the first comment I linked to above.
Comment #4
ANDiTKO CreditAttribution: ANDiTKO commentedOk i had no luck finding a proper solution for this. "Metatag:OpenGraph", "Metatag:OpenGraph Products" and "Token" modules were not working as expected. So i had to do this on my own.
Here is the code i used inside the "field--field_product_images.tpl.php" file:
In my case it worked perfectly. Make sure you wrap this inside an if that checks if
$element['#view_mode'] == 'node_full'