Hi,
I have a themed product page (node--product--type.tpl.php) with following setup:
* Images are set up on the Product with variations (and not the products display).
When I use the normal way (print render($content['product:field_product_largeimages']);) to display the images they change according to the current attribute (variation).
However, if I try to theme it in another way. The images don't get updated (they do get the initiatial image right) when changing attribute:
$lgImage = file_create_url($content['product:field_product_largeimages']['#items'][0]['uri']);
<img src="<?php echo $lgImage?>" />
Maybe I'm missing something essential here with what Ajax does with the page. Is it possible to retrieve images like this or do I need to use the render function to be able to use Ajax?
Cheers! /Mats
Comments
Comment #1
rszrama commentedSorry, per the issue submission guidelines, we do not offer such support in this queue. For future queries, please use http://www.drupalcommerce.org/questions. However, in your case, I can say that your problem should be self-evident - you're bypassing the normal output channel that wraps images in essential markup to handle updating inject fields. You're just going to have to look at the markup that works and figure out how to duplicate it - or, better yet, figure out a better solution to what you're trying to do. I don't think there's a situation where bypassing the output generated by Drupal so drastically would ever be a good idea.
Comment #2
matsjacobsson commentedThankyou Ryan!
Really appreciate it (and all your excellent work with drupal commerce to!)
I'm sorry I should have realized this is not a Drupal Commerce issue. I'll take your advice and try to archive it in a different way.
I think the way to go is to do it in the same way you handle cloud_zoom for the Commerce Kickstart.
Best regards,
Mats
Comment #3
rszrama commentedAlrighty, best of luck. The primary thing is that you have to be careful what processes you're overriding in theming - modules may be added essential classes or wrapper elements and then expecting them to be there when implementing functionality.
Comment #4
matsjacobsson commentedThanks! I managed to solve this with the using the custom formatter module and so far it seems to work great. Here is an example how the formatter could look like but you can use it the way you like.
/Mats
Comment #4.0
matsjacobsson commentedTypo error
Comment #5
matsjacobsson commentedI just want to share and update this with a fix to attach the javascript along with the ajax call.
Include the javascript that needs to trigger upon an ajax request with your template file like this:
drupal_add_js("sites/all/libraries/EXAMPLELIB/trigger-ajax.js", array('type' => 'file', 'scope' => 'header', 'weight' => 5));And for the javascript (trigger-ajax.js)
It does seem to fire a few times instead of just one. But at least thats better than not firing at all.. :)
/Mats