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.
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_*.
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
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" />
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>
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">
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">
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)
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'];
}
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.
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);
![]()
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
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
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();
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!');
Used to slugify a string. Uses https://github.com/cocur/slugify
$this->Slugify('This is a string');
this-is-a-string
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".
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>
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>
$tweets = $this->Twitter()->setLimit(2)->getItems();
foreach ($tweets as $tweet) {
$tweet->getText();
$tweet->getTextWithLinks() // embedded URLs converted to hyperlinks
$tweet->getCreatedAt();
$tweet->getSource();
}
$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'];
}
$nodes = $this->node->getCollection()->getRelated();
No related nodes for this node