अपडेट कर सकते हैं यह देखने के लिए कि मैं अपना खुद का ट्विग फ़िल्टर बनाकर इसे हल कर सकता हूं।
आप फ़िल्टर को उजागर करने के अपने स्वयं के मॉड्यूल बनाकर ऐसा कर सकते हैं।
इसे फिर से उपयोग करने के लिए स्वतंत्र महसूस करें।
कोड
namespace Drupal\twig_extender\TwigExtension;
use Drupal\node\Entity\Node;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
class Images extends \Twig_Extension {
/**
* Generates a list of all Twig functions that this extension defines.
*/
public function getFunctions(){
return array(
new \Twig_SimpleFunction('image_style', array($this, 'imageStyle'), array('is_safe' => array('html'))),
);
}
/**
* Gets a unique identifier for this Twig extension.
*/
public function getName() {
return 'twig_extender.twig.images';
}
/**
* Generate images styles for given image
*/
public static function imageStyle($file_id, $styles) {
$file = File::load($file_id);
$transform = array();
if (isset($file->uri->value)) {
$transform['source'] = $file->url();
foreach ($styles as $style) {
$transform[$style] = ImageStyle::load($style)->buildUrl($file->uri->value);
}
}
return $transform;
}
}
प्रयोग
{% set transform = image_style(image.entity.fid.value, ['thumbnail', 'large']) %}
तो फिर तुम & शैलियों
{{ transform.source }}
{{ transform.thumbnail }}
{{ transform.large }}
आशा है कि यह यो में मदद मिलेगी स्रोत छवि के लिए उपयोग किया
तुम आदमी!
स्रोत
2016-07-28 08:23:22
मैं वास्तव में सामग्री प्रकार सेटिंग्स में भी पाया, आप छवि सामग्री एक्स के लिए उस सामग्री प्रकार के लिए सभी छवियां प्रदर्शित कर सकते हैं। इसलिए मैं इसे अपने उत्तर या आपके से कर सकता हूं, लेकिन आपका बेहतर आईएमओ है। – Kato
"छवि" के लिए मुझे किस चर का उपयोग करना चाहिए? content.field_bloc_1_image.entity उदाहरण के लिए काम नहीं करता है: s –
मैं इसे काम पर नहीं मिला। यह छवि शैली का उपयोग नहीं करता है? मेरे पास {% सेट छवि = content.field_global_image | विलय ({'# image_style': 'थंबनेल'})%} {{image}} – paulcap1