2

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()) { ...}

4

1 回答 1

3

为此,您必须使用该text属性(请参阅WYSIWYG 的文档),因此它应该在您所做的前端中可见的第二个位置:

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

编辑:

使用块执行此操作可能需要使用块的手动模式,请参阅文档,然后为每个块获取所有子可编辑项的数据,否则您也会获得它们的重复名称。

您可以使用的另一个技巧是仅在前端输出响应部分,如果用户在前端,则仅打印第二次,如下所示:

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

虽然这样做的缺点是响应部分在编辑时不显示数据,但这可能不是问题,因为应该使用预览选项卡。

于 2014-04-01T22:15:58.357 回答