frontier_do_subtemplate

Processes template code within an each command from the base template.

Description

(null) frontier_do_subtemplate( (array) $atts, (string) $content ); 

Returns (null)

Parameters (2)

0. $atts (array)
Attributes from template
1. $content (string)
Template to be processed

Usage

  1. if ( !function_exists( 'frontier_do_subtemplate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'pods-custom-content-types-and-fields/components/Templates/includes/functions-view_template.php'; 
  3.  
  4. // attributes from template 
  5. $atts = array(); 
  6.  
  7. // template to be processed 
  8. $content = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = frontier_do_subtemplate($atts, $content); 
  12.  

Defined (1)

The function is defined in the following location(s).

/components/Templates/includes/functions-view_template.php  
  1. function frontier_do_subtemplate( $atts, $content ) { 
  2.  
  3. $out = null; 
  4. $pod =pods $atts[ pod ], $atts[ 'id' ] ); 
  5.  
  6. $params = array( 
  7. 'name' => $atts[ 'field' ],  
  8. ); 
  9.  
  10. $entries = $pod->field( $atts[ 'field' ] ); 
  11. if ( ! empty( $entries ) ) { 
  12.  
  13. /** 
  14. * Note on the change below for issue #3018: 
  15. * ... || 'taxonomy' == $pod->fields[ $atts[ 'field' ] ][ 'type' ] 
  16. * calling field() above for a taxonomy object field will populate 
  17. * $pod->fields[ $field_name ] for the object field's data, in this 
  18. * case a taxonomy object field. Without calling 
  19. * $pod->field( $field_name ), it would not normally be available in 
  20. * the $pod->fields array and is something to not expect to be there in 
  21. * 3.0 as this was unintentional. 
  22. */ 
  23. if ( ! empty( $pod->fields[ $atts[ 'field' ] ][ 'table_info' ] ) || 'taxonomy' == $pod->fields[ $atts[ 'field' ] ][ 'type' ] ) { 
  24. foreach ( $entries as $key => $entry ) { 
  25. $subpod =pods $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ] ); 
  26.  
  27. $subatts = array( 
  28. 'id' => $entry[ $subpod->api->pod_data[ 'field_id' ] ],  
  29. pod => $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ] 
  30. ); 
  31.  
  32. $template = frontier_decode_template( $content, array_merge( $atts, $subatts ) ); 
  33. $template = str_replace( '{_index}', $key, $template ); 
  34. $template = str_replace( '{@' . $atts[ 'field' ] . '.', '{@', $template ); 
  35.  
  36. // Kludge to work with taxonomies, pending a better solution: see issue #3018 
  37. $target_id = null; 
  38. if ( isset( $entry[ 'ID' ] ) ) { 
  39. $target_id = $entry[ 'ID' ]; 
  40. } elseif ( isset( $entry[ 'term_id' ] ) ) { 
  41. $target_id = $entry[ 'term_id' ]; 
  42.  
  43. $out .= pods_shortcode( array( 
  44. 'name' => $pod->fields[ $atts[ 'field' ] ][ 'pick_val' ],  
  45. 'slug' => $target_id,  
  46. 'index' => $key 
  47. ), $template ); 
  48.  
  49. } elseif ( 'file' == $pod->fields[ $atts[ 'field' ] ][ 'type' ] && 'attachment' == $pod->fields[ $atts[ 'field' ] ][ 'options' ][ 'file_uploader' ] && 'multi' == $pod->fields[ $atts[ 'field' ] ][ 'options' ][ 'file_format_type' ] ) { 
  50. $template = frontier_decode_template( $content, $atts ); 
  51. foreach ( $entries as $key => $entry ) { 
  52. $content = str_replace( '{_index}', $key, $template ); 
  53. $content = str_replace( '{@_img', '{@image_attachment.' . $entry[ 'ID' ], $content ); 
  54. $content = str_replace( '{@_src', '{@image_attachment_url.' . $entry[ 'ID' ], $content ); 
  55. $content = str_replace( '{@' . $atts[ 'field' ] . '}', '{@image_attachment.' . $entry[ 'ID' ] . '}', $content ); 
  56.  
  57. $out .= pods_do_shortcode( $pod->do_magic_tags( $content ), array( 
  58. 'each',  
  59. 'pod_sub_template',  
  60. 'once',  
  61. 'pod_once_template',  
  62. 'before',  
  63. 'pod_before_template',  
  64. 'after',  
  65. 'pod_after_template',  
  66. 'if',  
  67. 'pod_if_field' 
  68. ) ); 
  69.  
  70.  
  71. return pods_do_shortcode( $out, array( 
  72. 'each',  
  73. 'pod_sub_template',  
  74. 'once',  
  75. 'pod_once_template',  
  76. 'before',  
  77. 'pod_before_template',  
  78. 'after',  
  79. 'pod_after_template',  
  80. 'if',  
  81. 'pod_if_field' 
  82. ) );