Contao 4.4 Issue with Backend Element When using Stop Wrap div's
Closed this issue · 7 comments
I have installed contao 4.4.
For Dynamic content Element i'm using module 'agoat/contao-customcontentelements'.
I'm facing this issue in Backend. When i'm trying to use Start Wrap and Stop Wrap Custom Elements.
Problem might be for closing Which i'm using in Stop Wrap Elements. Please see below screen.
I will have a look into this. Maybe it's a wrong div wrapper in the backend preview..
But I would avoid Wrapper elements anyway. Just style the wrapping divs inside the custom elements template. To wrap multiple you can use the hidden functions (currently not documented) $this->prevElement
and $this->nextElement
to get the type of the surrounding element types and set the start/stop div blocks accordingly (see https://github.com/agoat/contao-customcontentelements-bundle/blob/master/src/Resources/contao/classes/Template.php#L197-L240).
The problem with the div wrapper ist related to how contao shows content elements in the backend (as a ul list). So it's not possible to use any kind of wrapper without invalidating the backend layout.
But I added another feature that allows you to select a backend template file for the content elements.
As mentioned on Stackoverflow, you should automatically generate a different output for the back end if an element is defined as a "wrapper".
One intention for using custom content elements, is to avoid complicated wrapper structures an editor has to deal with. As explained in my answer above #166 (comment) there are (currently undocumented) methods to handle first and last elements of a group (e.g. a portfolio) by setting wrapper elements inside the custom content template.
Here is a real world example (https://renderart.de/portfolio):
<?php if (TL_MODE == 'BE' || $this->prevElement() != $this->element): ?>
<div class="cb imagegrid">
<ul>
<?php endif; ?>
<li class="item">
<div class="teaser" <?php if (TL_MODE == 'BE') echo 'onclick="$(this).getParent().toggleClass(\'active\')"' ?>>
<figure>
<?php if ($this->teaserimage) { $this->insert('picture_default', $this->teaserimage);} ?>
</figure>
</div>
<div class="expander">
<div class="close"></div>
<div class="inner">
<h2 class="title"><?php echo $this->title; ?></h2>
<div class="type"><?php echo $this->projecttype; ?></div>
<div class="customer"><?php echo $this->customer; ?></div>
<div class="text"><?php echo $this->text; ?></div>
<?php if (is_array($this->images)): ?>
<div class="images col">
<?php foreach ($this->images as $image): ?>
<div>
<figure class="lb">
<?php $this->insert((TL_MODE == 'BE') ? 'picture_default' : 'picture_lightbox', $image['image']); ?>
</figure>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</li>
<?php if (TL_MODE == 'BE' || $this->nextElement() != $this->element): ?>
</ul>
</div>
<?php endif; ?>
One intention for using custom content elements, is to avoid complicated wrapper structures an editor has to deal with.
Not necessarily. You might still want to have a wrapper to do something arbitrary with arbitrary elements.
If you do not want to support wrapper elements with your extension that's fine of course. Then the use case of @AjayGohel is simply unsupported.
Then the use case of @AjayGohel is simply unsupported.
It is supported. You just have to use conditions in your template if (TL_MODE != 'BE')
, maybe in combination with the methods above.
Simple, isn't it. No need for extra element attributes.
I suppose, yeah ;)