View Helpers

View helpers allow you to retrieve data from the underlying database and remote APIs, manipulate images etc directly from the templates without having to modify the core controllers of MetaScale.

We make extensive use of the standard Zend Framework view helpers as well as our own custom view helpers with the Essential_View_Helper_* prefix.

Extended View Helpers

MetaScale 3.3 also allows you to create extended view helpers that compatible with the shortcode system by extending Essential_View_Helper_Abstract. These helpers have prefix Essential_View_Helper_Extended_*.


Essential_View_Helper_Ago

Converts an absolute past timestamp to a relative unit of time. E.g. "5 minutes ago", "2 days ago", "One year ago", etc.

$this->Ago(strtotime('2014-12-01')); // convert dates to timestamps first using strtotime()

11 years ago

Essential_View_Helper_HeadLink

Extends Zend_View_Helper_HeadLink and adds versioning based on file timestamp. Call the enableVersioning() method to trigger this feature (useful during development and preview to customer).

$this->headLink()->enableVersioning()->appendStylesheet('/design/default/css/style.css');

<link href="/design/default/css/style.css?v=1330644823" media="all" rel="stylesheet" type="text/css" />

Essential_View_Helper_HeadScript

Extends Zend_View_Helper_HeadScript and adds versioning based on file timestamp. Call the enableVersioning() method to trigger this feature (useful during development and preview to customer).

$this->headScript()->enableVersioning()->appendFile('/design/default/js/main.js');

<script type="text/javascript" src="/design/default/js/main.js?v=1326200364"></script>

Essential_View_Helper_HtmlClass

Used to add classes to the html tag based on the module, controller, and action of the current page as well as the application environment. Useful for styling purposes.

$this->HtmlClass();

<html class="module-default controller-page action-index default-page page-index default-page-index env-production">

Essential_View_Helper_BodyClass

Deprecated: Use Essential_View_Helper_HtmlClass instead for greater flexibility.

Used to add classes to the body tag based on the module, controller, and action of the current page as well as the application environment. Useful for styling purposes.

$this->BodyClass();

<body class="page module-default controller-page action-index default-page page-index default-page-index env-production">

Essential_View_Helper_Config

Fetches config values managed by the CMS System Configuration module and stored in the _config table.

$this->Config('website/name');

Website name: MetaScale CMS (Release 3.3.9)

Essential_View_Helper_Facebook

Fetches posts from Facebook API using /{page-id}/feed endpoint. Limit the number of posts using setLimit(). The Facebook page used in this example is at https://www.facebook.com/pages/Example-page-for-documentation/504886336343558


    $posts = $this->Facebook()->setLimit(2)->getItems();
    foreach ($posts as $post) {
        $post['message'];
        $post['created_time'];
    }
            
Essential_View_Helper_GoogleAnalytics

Renders the standard Global site tag (gtag.js) snippet. This helper should be positioned immediately after the opening <head> element.

$this->GoogleAnalytics($this->Config('google-analytics/ua'));  // config value is passed in using Essential_View_Helper_Config.
<!-- Position immediately after the head tag -->
        <!-- Global site tag (gtag.js) - Google Analytics -->
        <script async src="https://www.googletagmanager.com/gtag/js?id=UA-999999"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'UA-999999');
        </script>
Essential_View_Helper_HtmlPageDom

Used to manipulate a HTML fragment using jQuery like selectors. Returns a \Wa72\HtmlPageDom\HtmlPageCrawler object. Uses https://github.com/wasinger/htmlpagedom

The HTML supplied will be wrapped in a span.processed-by-html-page-dom class by default. To remove the wrapper supply '%s' as the second argument.

$dom = $this->HtmlPageDom('<p>This is a lead paragraph.</p>');
$dom->filter('p')->addClass('lead');
print $dom;

This is a lead paragraph.

Essential_View_Helper_Image (Original 1920x1080 Image)

Used to optimise and crop images retrieved using the getImages() method of a model.

Resize to width (with auto height)

$this->Image($img)->setWidth(150); // $img is an instance of Application_Model_Image()

Resize to width and height (with auto crop)

$this->Image($img)->setWidth(150)->setHeight(50);

Resize to width and height (with auto crop) and set output quality to 5

$this->Image($img)->setWidth(150)->setHeight(150)->setQuality(5);

Fill with red at 50% opacity, resize to width (with auto height)

$this->Image($img)->fill('#ff0000', 50)->setWidth(150);

Grayscale, resize to width (with auto height)

$this->Image($img)->grayscale()->setWidth(150);

Negative, resize to width (with auto height)

$this->Image($img)->negative()->setWidth(150);

Essential_View_Helper_LinkifyInstagram

Linkifies URLs, users and hashtags in Instagrams. Links will open in new _blank window.

$this->LinkifyInstagram("@NASA Tomorrow the unit on #ESA_Rosetta that's listening out for #Philae2014 will be turned off #goodbyePhilae http://www.esa.int/ESA");

@NASA Tomorrow the unit on #ESA_Rosetta that's listening out for #Philae2014 will be turned off #goodbyePhilae http://www.esa.int/ESA

Essential_View_Helper_LinkifyTweet

Linkifies URLs, users and hashtags in tweets. Links will open in new _blank window.

$this->LinkifyTweet("@Philae2014 Looks like everything went smoothly! It's always nice to phone back #home, isn't it @NASANewHorizons? #PlutoFlyby http://www.esa.int/ESA");

@Philae2014 Looks like everything went smoothly! It's always nice to phone back #home, isn't it @NASANewHorizons? #PlutoFlyby http://www.esa.int/ESA

Essential_View_Helper_Node

Fetch a single node from another part of the website, then use getCollection()->getVisibleChildren() on the returned Application_Model_Node() to display all of its sub-nodes.

$nodes = $this->Node('example-templates')->getCollection()->getVisibleChildren();

Page using standard template

  • Meta Title: Page using standard template
  • Meta Description:

Page using image on top template

  • Meta Title: Page using image on top template
  • Meta Description:

Page using image on right template

  • Meta Title: Page using image on right template
  • Meta Description:

Page using image on left template

  • Meta Title: Page using image on left template
  • Meta Description:

Contact form (using AJAX)

  • Meta Title: Contact Form (using AJAX)
  • Meta Description:

Page using image on top template with extra content fields

  • Meta Title: Page using image on top template with extra content fields
  • Meta Description:
Essential_View_Helper_QrCode

Uses the Google Chart API to render a QR Code for the current URL (can be overridden with setData() method). Other methods are setSize(), setMargin(), setErrorCorrectionLevel()

$this->QrCode()->setSize('100x100')->setData('Hello World!');

Essential_View_Helper_Slugify

Used to slugify a string. Uses https://github.com/cocur/slugify

$this->Slugify('This is a string');

this-is-a-string

Essential_View_Helper_Extended_StaticBlock

Used to fetch content managed by the CMS Static Blocks module.

$this->StaticBlockItem()->setIdentifier('test-block');

I am a richtext Static Block named "Test Block". My id is 1 and my identifier is "test-block".

Essential_View_Helper_Scraper

Used to screen scrape/leech HTML content from another website. Values supplied to setStartTag() and setEndTags() will be processed by preg_match() so make sure they have been escaped correctly. Start and end tags could also be HTML comments so you're not just limited to using HTML elements.

$this->Scraper()->setUrl('https://www.example.org/')->setStartTag('<body>')->setEndTag('<\/body>');
<div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div>
Essential_View_Helper_YesNo

Basic view helper to represent 1 and 0 as Yes and No. Outputs No if supplied value isn't 1. Normally used for CMS flags such as is_visible, is_featured etc.

$this->YesNo(0);
<span class="yn yn-no">No</span>

$this->YesNo(1);
<span class="yn yn-yes">Yes</span>
Essential_View_Helper_Twitter (Deprecated, used old Twitter API)

	$tweets = $this->Twitter()->setLimit(2)->getItems();

	foreach ($tweets as $tweet) {
		$tweet->getText();
		$tweet->getTextWithLinks()	// embedded URLs converted to hyperlinks
		$tweet->getCreatedAt();
		$tweet->getSource();
	}
	
Essential_View_Helper_Rss

    $feed = $this->Rss()->setUrl('http://feeds.feedburner.com/EssentialLogic')->setLimit(3)->getItems();

    $feed['title']
    $feed['link']
    $feed['dateModified']
    $feed['description']
    $feed['language']

    foreach ($feed['entries'] as $entry) {
        $author = $entry['authors'];

        $entry['title'];
        $entry['description'];
        $entry['dateModified'];
        $author[0]['name'];
        $entry['link'];
        $entry['content'];
    }
            
  • Essential Logic
  • https://essentiallogic.co.uk
  • 14 мая 2025 г. 14:26:10
  • Web development | Shopify | Birmingham UK
  • en-GB
Related nodes
$nodes = $this->node->getCollection()->getRelated();

No related nodes for this node