Search code examples
phppimcore

Save editables to variable and then print


I am currently exploring pimcore and its editables. So I want to have a dynamic list with social media icons that is editable in the backend. I created a snippet.

So I am using the block editable like this:

<?php

while ($this->block("social-media")->loop()) {

  if($this->editmode) {

    print $this->link('social-media-link');
    print $this->image('social-media-icon', [ 'width' => 30, 'height' => 30 ]);

  }
  else {

    print "<a href=\"{$this->link('social-media-link')->getHref()}\">{$this->image('social-media-icon', [ 'width' => 30, 'height' => 30 ])}</a>";

  }

}

This works as expected. But now I want to get rid of the duplication. To achive this, I tried this:

<?php

while ($this->block("social-media")->loop()) {

  $objCurrentSocialMediaLink = $this->link('social-media-link');
  $objCurrentSocialMediaIcon = $this->image('social-media-icon', [ 'width' => 30, 'height' => 30 ]);

  if($this->editmode) {

    print $objCurrentSocialMediaLink;
    print $objtCurrentSocialMediaIcon;

  }
  else {

    print "<a href=\"{$objCurrentSocialMediaLink->getHref()}\">{$objCurrentSocialMediaIcon}</a>";

  }

}

But this does not work. The backend renders only the link editable. Does anyone know why and what I am doing wrong?


Solution

  • You are not printing the correct variable. Remove the "t" in this variable:

    print $objtCurrentSocialMediaIcon;

    Should be:

    print $objCurrentSocialMediaIcon;