获取子字段()

上次更新时间:2024年2月6日

描述

从中继器或灵活内容字段循环返回特定子字段值的值。

参数

获取子字段($选择器,[$format_value=true],[$escape_html=false]);
  • $选择器 (字符串) (必需)子字段名称或字段键。
  • $格式_值 (布尔) (可选)是否应用格式逻辑。默认为true。
  • $escape_html (布尔) (可选)自6.2.6起–返回字段值的转义HTML安全版本。要求$format_value为true。默认为false。

返回

(混合)子字段值。

示例

从Repeater字段中获取值。

此示例显示如何循环通过Repeater字段并加载子字段值。

if(have_rows('parent_field')):while(have_rows('parent_field')):the_row();$sub_value=获取子字段('sub_field');//做点什么。。。endwhile;其他://找不到行endif;

从“灵活内容”字段中获取值。

此示例显示如何循环访问“灵活内容”字段并加载子字段值。

if(have_rows('parent_field')):while(have_rows('parent_field')):the_row();//布局1。如果(get_row_layout()==“布局1”)://布局1值。$值=获取子字段('sub_field_1');//布局2。elseif(get_row_layout()==“布局_2”)://布局2值。$值=获取子字段('sub_field_2');endif;结束时;endif;

嵌套循环连接

此示例显示如何循环通过嵌套的Repeater字段并加载子字段值。

/***字段结构:**-parent_repeater(中继器)*-parent_title(文本)*-child_repeater(中继器)*-child_title(文本)*/if(have_rows(“父转发器”):while(have_rows('parent_reporter')):the_row();//获取父值。$parent_title=获取子字段(“父标题”);//在子转发器行上循环。if(have_rows('child_reporter')):while(have_rows('child_reporter')):the_row();//获取子值。$child_title=获取子字段('child_ttitle');endwhile;endif;结束时;endif;

相关的