ds20021205 2011-08-31 15:26
浏览 51
已采纳

Drupal 7使用field_view_value()获取预告片

I have an Ajax handler script where I load a $nodeId and output the result in default (full) view:

$node = node_load($input);
$prerendered_node = node_view( $node, 'default' );
...

Now I need to display the teaser (summary or trimmed) as well.

I tried this so far, without success (summary is filled in content):

1.
$item = $node->body['en'][0];
$output = field_view_value('node', $node, 'body', $item, 'Teaser');
echo $output; (blank)

2. echo $node->body['eng']['0']['summary']; (blank)

A solution from this question but not working:

3. $output = truncate_utf8(strip_tags($node->body['eng']['0']['summary']),200,true,true);
echo $output; (blank)

Curious is that var_dump($node->body['eng']['0']) displays and array containing value (of body), summary, clean_summary and other elements and the summary has the necessary value filled. But as in example 2 I can't directly access it, it's coming up blank on display.

Tips, please?

Thank you.

  • 写回答

2条回答 默认 最新

  • duannao1920 2011-08-31 17:56
    关注

    I guess this a multi-lingual site otherwise you'd probably find what you were looking for in $node->body['und'][0] (i.e. und, the undefined language code)?

    Your 1st solution should work, only you've used Teaser instead of teaser, I'm pretty sure the view mode is case sensitive. Also you've got $node->body['en'][0] (language code of en) whereas you've used the language code eng in all of the other examples...could that be the problem?

    Your 2nd solution would simply have to work if $node->body['eng']['0']['summary'] was not empty so I'd check again that your var_dump() is producing accurate results (are you inspecting the output of var_dump() immediately after you call $node = node_load($input); to make it a fair test, for example).

    Similarly if your 3rd solution is outputting a blank string it means $node->body['eng']['0']['summary'] absolutely must be empty.

    I'd strongly recommend installing the devel module and using the dpm() function to print a nicely formatted, hierarchical view of objects/arrays for inspection. If you can't do that Drupal 7 has a debug() function which does something similar. The output of both of these functions is printed to the standard Drupal message space.

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?