Search code examples
phpresponsive-designpimcore

Read a field, so that its is not editable in pimcore CMS, because of duplicated fields because of responsiveness


How can I read only an element in pimcore?

Normally, I create an element like this:

$this->wysiwyg("content");

So, it writes the text from the element content in the frontend, and I can edit it on the backend.

But I need to write this twice in the frontend, because of my responsive design. But then it gives a error in the backend because of duplicate element name 'content'.

My approach: First I use $this->wysiwyg("content"); and second I use ??? to only read the text of the element for the frontend (no editable element in the backend). But how?

Edit: And how can I solve this for my block-element? Error message in backend: Dublicate editable name: contentblock Code: while($this->block("contentblock")->loop()) { ...}


Solution

  • You have to use the text property (see the documentation for WYSIWYG) for this, so the second place it should be visible in the frontend you do:

    <?php echo $this->wysiwyg("content")->text; ?>
    

    Edit:

    Doing it with blocks would probably require using the manual mode of the block, see the documentation and then for each block just get the data for all child editables, because otherwise you will get the duplicate name for them too.

    Another trick you could use is to only output the responsive part in the frontend, by only printing the second time if the user is in the frontend, like this:

    <?php if(!$this->editmode) { ?>
        <?php while($this->block("contentblock")->loop()) { ?>
            <?php echo $this->wysiwyg("content"); ?>
        <?php } ?>
    <?php } ?>
    

    Although this has the disadvantage of the responsive part not showing the data while editing, but that might not be a problem since the preview tab should be used for that.