Skip to main content

GravityView_View

Source: includes/class-template.php:26

Details

  • Kind: class
  • Namespace: (global)
  • Extends: GV\Gamajo_Template_Loader

Properties

PropertyTypeDescription
$filter_prefixstringPrefix for filter names.
$theme_template_directorystringDirectory name where custom templates for this plugin should be found in the theme.
$plugin_directorystringReference to the root directory path of this plugin.
$located_templatesarrayStore templates locations that have already been located
$template_part_slugstringThe name of the template, like "list", "table", or "datatables"
$template_part_namestringThe name of the file part, like "body" or "single"
$form_idintGravity Forms form ID
$view_idintView ID
$fieldsarrayFields for the form
$contextstringCurrent screen. Defaults to "directory" or "single"
$post_idint | nullIf in embedded post or page, the ID of it
$formarrayGravity Forms form array at ID $form_id
$attsarrayConfiguration for the View
$entriesarrayEntries for the current result. Single item in array for single entry View
$total_entriesintTotal entries count for the current result.
$back_link_labelstringThe label to display back links
$pagingarrayArray with offset and page_size keys
$sortingarrayArray with sort_field and sort_direction keys
$hide_until_searchedboolWhether to hide the results until a search is performed
$_current_entryarrayCurrent entry in the loop
$_current_fieldarray
$field_dataThe current field data.

Methods

MethodDescription
__construct()Construct the view object
getInstance()
getCurrentField()
setCurrentField()
getAtts()
setAtts()
getForm()
setForm()
getPostId()
setPostId()
getContext()
setContext()
getFields()
getContextFields()Get the fields for a specific context
setFields()
getField()
setField()
getViewId()
setViewId()
getFormId()
setFormId()
getEntries()
setEntries()
getTotalEntries()
setTotalEntries()
getPaging()
setPaging()
getPaginationCounts()Get an array with pagination information
getSorting()
setSorting()
getBackLinkLabel()
setBackLinkLabel()
isHideUntilSearched()
setHideUntilSearched()
getTemplatePartSlug()
setTemplatePartSlug()
getTemplatePartName()
setTemplatePartName()
getCurrentEntry()Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.
setCurrentEntry()
clearCurrentEntry()Clear the current entry after all entries in the loop have been displayed.
renderZone()Render an output zone, as configured in the Admin
locate_template()In order to improve lookup times, we store located templates in a local array.
__get()Magic Method: Instead of throwing an error when a variable isn't set, return null.
add_id_specific_templates()Enable overrides of GravityView templates on a granular basis
render()Render a template part
render_widget_hooks()Output the widgets on before/after hooks.
_include()Include a file inside this context.

Method Reference

__construct()

function __construct( $atts=[] )

Construct the view object

Parameters

NameTypeDefaultDescription
$attsarray[]Associative array to set the data of

Source: includes/class-template.php:182

getInstance()

static function getInstance( $passed_post=null )

Parameters

NameTypeDefaultDescription
$passed_postnullnull

Returns

Source: includes/class-template.php:226

getCurrentField()

public function getCurrentField( $key=null )

Parameters

NameTypeDefaultDescription
$keystring | nullnullThe key to a specific attribute of the current field

Returns

  • array | mixed | null — If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array

Source: includes/class-template.php:239

setCurrentField()

public function setCurrentField( $passed_field )

Parameters

NameTypeDefaultDescription
$passed_fieldarray

Source: includes/class-template.php:271

getAtts()

public function getAtts( $key=null )

Parameters

NameTypeDefaultDescription
$keystring | nullnullThe key to a specific field in the fields array

Returns

  • array | mixed | null — If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.

Source: includes/class-template.php:291

setAtts()

public function setAtts( $atts )

Parameters

NameTypeDefaultDescription
$attsarray

Source: includes/class-template.php:306

getForm()

public function getForm()

Returns

  • array

Source: includes/class-template.php:313

setForm()

public function setForm( $form )

Parameters

NameTypeDefaultDescription
$formarray

Source: includes/class-template.php:320

getPostId()

public function getPostId()

Returns

  • int | null

Source: includes/class-template.php:327

setPostId()

public function setPostId( $post_id )

Parameters

NameTypeDefaultDescription
$post_idint | null

Source: includes/class-template.php:334

getContext()

public function getContext()

Returns

  • string

Source: includes/class-template.php:341

setContext()

public function setContext( $context )

Parameters

NameTypeDefaultDescription
$contextstring

Source: includes/class-template.php:348

getFields()

public function getFields( $key=null )

Parameters

NameTypeDefaultDescription
$keystring | nullnullThe key to a specific field in the fields array

Returns

  • array | mixed | null — If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.

Source: includes/class-template.php:356

getContextFields()

public function getContextFields( $context='' )

Get the fields for a specific context

Parameters

NameTypeDefaultDescription
$contextstring''[Optional] "directory", "single", or "edit"

Returns

  • array — Array of GravityView field layout configurations

Since: 1.19.2

Source: includes/class-template.php:376

setFields()

public function setFields( $fields )

Parameters

NameTypeDefaultDescription
$fieldsarray

Source: includes/class-template.php:400

getField()

public function getField( $key )

Parameters

NameTypeDefaultDescription
$keystringThe key to a specific field in the fields array

Returns

  • array | mixed | null — If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.

Source: includes/class-template.php:408

setField()

public function setField( $key, $value )

Parameters

NameTypeDefaultDescription
$keystringThe key to a specific field in the fields array
$valuemixedThe value to set for the field

Source: includes/class-template.php:423

getViewId()

public function getViewId()

Returns

  • int

Source: includes/class-template.php:430

setViewId()

public function setViewId( $view_id )

Parameters

NameTypeDefaultDescription
$view_idint

Source: includes/class-template.php:437

getFormId()

public function getFormId()

Returns

  • int

Source: includes/class-template.php:444

setFormId()

public function setFormId( $form_id )

Parameters

NameTypeDefaultDescription
$form_idint

Source: includes/class-template.php:451

getEntries()

public function getEntries()

Returns

  • array

Source: includes/class-template.php:458

setEntries()

public function setEntries( $entries )

Parameters

NameTypeDefaultDescription
$entriesarray

Source: includes/class-template.php:465

getTotalEntries()

public function getTotalEntries()

Returns

  • int

Source: includes/class-template.php:472

setTotalEntries()

public function setTotalEntries( $total_entries )

Parameters

NameTypeDefaultDescription
$total_entriesint

Source: includes/class-template.php:479

getPaging()

public function getPaging()

Returns

  • array

Source: includes/class-template.php:486

setPaging()

public function setPaging( $paging )

Parameters

NameTypeDefaultDescription
$pagingarray

Source: includes/class-template.php:499

getPaginationCounts()

public function getPaginationCounts()

Get an array with pagination information

Returns

  • array — {

Since: 1.13

Source: includes/class-template.php:514

getSorting()

public function getSorting()

Returns

  • array

Source: includes/class-template.php:551

setSorting()

public function setSorting( $sorting )

Parameters

NameTypeDefaultDescription
$sortingarray

Source: includes/class-template.php:565

getBackLinkLabel()

public function getBackLinkLabel( $do_replace=true )

Parameters

NameTypeDefaultDescription
$do_replacebooleantruePerform merge tag and shortcode processing on the label. Default: true.

Returns

  • string

Since: 2.0

Deprecated: Use $template->get_back_label();

Source: includes/class-template.php:577

setBackLinkLabel()

public function setBackLinkLabel( $back_link_label )

Parameters

NameTypeDefaultDescription
$back_link_labelstring

Source: includes/class-template.php:589

isHideUntilSearched()

public function isHideUntilSearched()

Returns

  • boolean

Source: includes/class-template.php:596

setHideUntilSearched()

public function setHideUntilSearched( $hide_until_searched )

Parameters

NameTypeDefaultDescription
$hide_until_searchedboolean

Source: includes/class-template.php:603

getTemplatePartSlug()

public function getTemplatePartSlug()

Returns

  • string

Source: includes/class-template.php:610

setTemplatePartSlug()

public function setTemplatePartSlug( $template_part_slug )

Parameters

NameTypeDefaultDescription
$template_part_slugstring

Source: includes/class-template.php:617

getTemplatePartName()

public function getTemplatePartName()

Returns

  • string

Source: includes/class-template.php:624

setTemplatePartName()

public function setTemplatePartName( $template_part_name )

Parameters

NameTypeDefaultDescription
$template_part_namestring

Source: includes/class-template.php:631

getCurrentEntry()

public function getCurrentEntry()

Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.

Returns

  • array

Source: includes/class-template.php:640

setCurrentEntry()

public function setCurrentEntry( $current_entry )

Parameters

NameTypeDefaultDescription
$current_entryarray

Returns

  • void

Source: includes/class-template.php:661

clearCurrentEntry()

public function clearCurrentEntry()

Clear the current entry after all entries in the loop have been displayed.

Returns

  • void

Since: 1.7.3

Source: includes/class-template.php:671

renderZone()

public function renderZone( $zone='', $atts=[], $echo=true )

Render an output zone, as configured in the Admin

Parameters

NameTypeDefaultDescription
$zonestring''The zone name, like 'footer-left'
$attsarray[]
$echobooltrueWhether to print the output

Returns

  • string | null

Since: 1.16.4 (Added $echo parameter)

Deprecated: This will never get called in new templates.

Source: includes/class-template.php:688

locate_template()

function locate_template( $template_names, $load=false, $require_once=true )

In order to improve lookup times, we store located templates in a local array.

This improves performance by up to 1/2 second on a 250 entry View with 7 columns showing

Parameters

NameTypeDefaultDescription
$template_namesstring | arrayTemplate file(s) to search for, in order.
$loadboolfalseIf true the template file will be loaded if it is found.
$require_oncebooltrueWhether to require_once or require. Default true. Has no effect if $load is false.

Returns

  • null | string — NULL: Template not found; String: path to template

See Also

  • \Gamajo_Template_Loader::locate_template()

Since: 1.0.0

Source: includes/class-template.php:780

__get()

public function __get( $name )

Magic Method: Instead of throwing an error when a variable isn't set, return null.

Parameters

NameTypeDefaultDescription
$namestringKey for the data retrieval.

Returns

  • mixed | null — The stored data.

Source: includes/class-template.php:809

add_id_specific_templates()

function add_id_specific_templates( $templates, $slug, $name )

Enable overrides of GravityView templates on a granular basis

The loading order is:

  • view-[View ID]-table-footer.php
  • form-[Form ID]-table-footer.php
  • page-[ID of post or page where view is embedded]-table-footer.php
  • table-footer.php

Parameters

NameTypeDefaultDescription
$templatesarrayExisting list of templates.
$slugstringName of the template base, example: table, list, datatables, map
$namestringName of the template part, example: body, footer, head, single

Returns

  • array — $templates Modified template array, merged with existing $templates values

See Also

  • \Gamajo_Template_Loader::get_template_file_names() Where the filter is

Source: includes/class-template.php:834

render()

public function render( $slug, $name, $require_once=true, $data=[] )

Render a template part

Parameters

NameTypeDefaultDescription
$slugstringThe template slug (like "table").
$namestringThe template part name (like "body").
$require_oncebooltrueWhether to require_once the template file. Default: true.
$dataarray[]Data to pass to the template, available to the template as a $data global. Default: array().

Since: 2.42

Source: includes/class-template.php:870

render_widget_hooks()

public function render_widget_hooks( $view_id_or_context )

Output the widgets on before/after hooks.

Parameters

NameTypeDefaultDescription
$view_id_or_contextint | \GV\Template_ContextThe View ID or the context.

Returns

  • void

Source: includes/class-template.php:903

_include()

public function _include( $path )

Include a file inside this context.

Parameters

NameTypeDefaultDescription
$pathstringA path to the legacy template to include.

Returns

  • void

Source: includes/class-template.php:1068