Re: Designer Contentで作成したブロックをページリストテンプレート内で表示したいです

2015年4月25日 at 23:01

endoさん

ありがとうございます。
試して見たのですが下記のようなエラーが返ってきてしまいました。


Fatal error: Call to private method MenuBlockController::get_image_object() from context 'Concrete5_Library_BlockView' in



エラーとなっているコードは下記になります。
※要素名は自分の環境に合わせて変更しています。

$bObj->set('field_1_image', (empty($bObj->field_1_image_fID) ? null : $bObj->get_image_object($bObj->field_1_image_fID, $width, $height, true)));




お教え頂いたコード以外に何か記載しないといけないコードなどありますでしょうか。

タグ:

Re: Designer Contentで作成したブロックをページリストテンプレート内で表示したいです

2015年4月26日 at 0:34
contiさん

失礼しました。

get_image_object は、Designer Contetntで作成した、contollerに定義される、
private functionですね。
(相変わらず、コードの動作未検証ですが、get_image_objectのロジックを持ってきてみました)

// get instance of the block
if (is_object($blocks[0])) {
$bObj = $blocks[0]->getInstance();
// print property of the block (Designer Content style)
echo $bObj->field_1_textbox_text;


// set field_2_image from field_2_image_fID
if (!empty($bObj->field_2_image_fID)) {
$file = File::getByID($bObj->field_2_image_fID);
$ih = Loader::helper('image');

// set for width and hight attribute for image tag
$width = 200;
$width = 400;
$image = $ih->getThumbnail($file, $width, $height, true);

$bObj->set('field_2_image', $image);
}
if (!empty($field_2_image)) { ?>
<img src="<?php echo $field_2_image->src; ?>" width="<?php echo $field_2_image->width; ?>" height="<?php echo $field_2_image->height; ?>" />
<?php
}
}
 

Re: Designer Contentで作成したブロックをページリストテンプレート内で表示したいです

2015年4月26日 at 0:59
自分で提示しておいて、恥ずかしいですが、ちょっとコードが汚いですね。

折角、imageヘルパーを使っているので、outputThumbnailでimgタグを出力してあげた方が、
concrete5っぽくてスマートに成ります。