GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gv-context-template.php
Go to the documentation of this file.
1 <?php
2 namespace GV;
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * A template Context class.
11  *
12  * This is provided to most template files as a global.
13  */
14 class Template_Context extends Context {
15  /**
16  * @var \GV\Template The template.
17  */
18  public $template;
19 
20  /**
21  * @var \GV\View The view.
22  */
23  public $view;
24 
25  /**
26  * @var \GV\Entry The entry. If single-entry view.
27  */
28  public $entry;
29 
30  /**
31  * @var \GV\Entry_Collection The entries. If directory view.
32  */
33  public $entries;
34 
35  /**
36  * @var \GV\Field_Collection The fields.
37  */
38  public $fields;
39 
40  /**
41  * @var \GV\Field The field. When rendering a single field.
42  */
43  public $field;
44 
45  /**
46  * @var \GV\Source The data source for a field.
47  */
48  public $source;
49 
50  /**
51  * @var mixed The display value for a field.
52  */
54 
55  /**
56  * @var mixed The raw value for a field.
57  */
58  public $value;
59 
60  /**
61  * @var \GV\Request The request.
62  */
63  public $request;
64 
65  /**
66  * Create a context from a Template
67  *
68  * @param \GV\Template|array $template The template or array with values expected in a template
69  * @param array $data Additional data not tied to the template object.
70  *
71  * @return \GV\Template_Context The context holder.
72  */
73  public static function from_template( $template, $data = array() ) {
74  $context = new self();
75 
76  $context->template = $template;
77 
78  /**
79  * Data.
80  */
81  $context->display_value = Utils::get( $data, 'display_value' );
82  $context->value = Utils::get( $data, 'value' );
83 
84  /**
85  * Shortcuts.
86  */
87  $context->view = Utils::get( $template, 'view' );
88  $context->source = Utils::get( $template, 'source' );
89  $context->field = Utils::get( $template, 'field' ) ? : Utils::get( $data, 'field' );
90  $context->entry = Utils::get( $template, 'entry' ) ? : Utils::get( $data, 'entry' );
91  $context->request = Utils::get( $template, 'request' );
92 
93  $context->entries = Utils::get( $template, 'entries' ) ? $template->entries : null;
94  $context->fields = $context->view ? $context->view->fields : null;
95 
96  return $context;
97  }
98 }
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
If this file is called directly, abort.
If this file is called directly, abort.
static from_template( $template, $data=array())
Create a context from a Template.