JReviews logo Docs
Menu
Version

before_theme_render_viewvars

Filter view variables before these are sent to the template.

Filter
System

You need to have a working knowledge of Hooks before you get started.

The filter has one additional variation that allows targeting a specific action within a controller without the need for additional checks.

before_theme_render_viewvars_{name}_{action}

Where {name} is the controller name and {action} is the controller method.

Parameters

Name Type Description
$viewVars parameter (array) associative array of template variables
$params parameter (array) associative array with contextual data

Boilerplate Code

Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.

Clickfwd\Hook\Filter::add('before_theme_render_viewvars', function($viewVars, $params)
{
    // Uncomment line below to view available data passed into hook
    // fwd_dd($viewVars, $params);

    return $viewVars;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

Examples

Apply SEO title tag replacement for listing heading in listing detail page only

The coer SEO title tag replacement functionality performs the title replacements in listing detail and list pages. If you'd like to limit it to just the detail page you can disable the title replacement setting and use this filter.

Clickfwd\Hook\Filter::add('before_theme_render_viewvars_com_content_com_content_view', function($viewVars, $params) 
{
    // Read the SEO title from the listing type configuration
    $config = S2Object::make('config');

    $config->withType($viewVars['listing']['ListingType']['listing_type_id']);

    $title = $config->get('type_metatitle', '{title}');
    
    // Apply the tags replacement filter
    $title = \Clickfwd\Hook\Filter::filter('listing_replace_tags', $title, [[
        'listing'=> $viewVars['listing'],
    ]]);

    // Modify the listing heading
    $viewVars['listing']['Listing']['title'] = $title;
  
  return $viewVars;
});

Source Files

  • /controllers/my_controller.php