Jump to content

Error: Call to a member function getTag() on a non-object


hellomoto
 Share

Recommended Posts

			$blocks = '';
			foreach($page->home_blox as $block) {
				$bgimg = '';
				if($block->pg->images->getTag('blockbg'))
					$bgimg = "<img src='{$block->pg->images->getTag('blockbg')->url}'/>";
				
				$filters = '';
				foreach($block->home_filters as $filter) {
					$filters .= " --{$filter->value}";
				}

				$body = $block->pg->get('summary|body');

				$output = <<<EOT

		    <div class="unit-{$block->home_blockwidth}0 element-item{$filters}">
		        <div class="background">{$bgimg}</div>
		        <div class="overlay">
		            <header><h2 class="title"><i class="fa fa-clock-o"></i> {$block->pg->title}</h2></header>
		            <div class="inner">
		                {$body}
		            </div>
		        </div>
		    </div>

EOT;
				$blocks .= $output;
			}
			echo $blocks;

I have tags enabled on the image field, so why am I getting this error?

Link to comment
Share on other sites

What is $block? What is pg? Is the image field actually called 'images'?

$block is a single item in the repeater field "home_blox". $block->pg is the Page field within the repeater. Image field is named "images".

This worked:

	foreach($page->home_blox as $block) {
		$bgimg = '';
		$pg = $block->pg;
		if($pg->images->getTag('blockbg')) {
			$bgimg = "<img src='{$pg->images->getTag('blockbg')->url}'/>";
		}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...