Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

news_latest template does not check for addBefore #6731

Closed
fritzmg opened this issue Feb 12, 2014 · 6 comments
Closed

news_latest template does not check for addBefore #6731

fritzmg opened this issue Feb 12, 2014 · 6 comments
Labels

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Feb 12, 2014

Even though you are able to define the 4 different positions of the teaser image for a news entry (before, after, float left, float right), the news_latest template only considers the floating property, but not the addBefore property. Setting the image to 'after' has no effect in the default news_latest template.

A news_latest template, that actually considers this setting could look like this:

<div class="layout_latest block<?php echo $this->class; ?>">

  <?php if ($this->hasMetaFields): ?>
    <p class="info"><time datetime="<?php echo $this->datetime; ?>"><?php echo $this->date; ?></time> <?php echo $this->author; ?> <?php echo $this->commentCount; ?></p>
  <?php endif; ?>

  <h2><?php echo $this->linkHeadline; ?></h2>

  <?php if (!$this->addBefore): ?>
  <div class="teaser">
    <?php echo $this->teaser; ?>
  </div>
  <?php endif; ?>

  <?php if ($this->addImage): ?>
    <figure class="image_container<?php echo $this->floatClass; ?>"<?php if ($this->margin || $this->float): ?> style="<?php echo trim($this->margin . $this->float); ?>"<?php endif; ?>>

      <?php if ($this->href): ?>
        <a href="<?php echo $this->href; ?>"<?php echo $this->attributes; ?> title="<?php echo $this->alt; ?>">
      <?php endif; ?>

      <img src="<?php echo $this->src; ?>"<?php echo $this->imgSize; ?> alt="<?php echo $this->alt; ?>">

      <?php if ($this->href): ?>
        </a>
      <?php endif; ?>

      <?php if ($this->caption): ?>
        <figcaption class="caption" style="width:<?php echo $this->arrSize[0]; ?>px"><?php echo $this->caption; ?></figcaption>
      <?php endif; ?>

    </figure>
  <?php endif; ?>

  <?php if ($this->addBefore): ?>
  <div class="teaser">
    <?php echo $this->teaser; ?>
  </div>
  <?php endif; ?>

  <?php if ($this->text): ?>
    <p class="more"><?php echo $this->more; ?></p>
  <?php endif; ?>

</div>
@leofeyer leofeyer modified the milestones: 3.2.6, 3.2.7 Feb 12, 2014
@leofeyer leofeyer removed this from the 3.2.8 milestone Mar 10, 2014
@leofeyer
Copy link
Member

Correct, the template does not support "add before" and "add after". Not every template supports every possible setting, e.g. the news_short and news_simple templates do not even support teaser images at all. It is up to you to create a template which meets your requirements.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 11, 2014

Correct, the template does not support "add before" and "add after". Not every template supports every possible setting, e.g. the news_short and news_simple templates do not even support teaser images at all.

Of course, thus you would expect if one of the default templates does support the teaser image, it would also support all the properties for the teaser image. Just like you would expect the default template for the Text Content Element for example to do the same.

@leofeyer
Copy link
Member

I don't agree. And your change implies a BC break, so no way it's going to be applied.

@fritzmg
Copy link
Contributor Author

fritzmg commented Mar 18, 2014

And your change implies a BC break, so no way it's going to be applied.

Yes, I am sorry, I forgot that the template I posted already had some other changes in it as well (I took it from another project of mine). The following would be a default news_latest template that does not break BC:

<div class="layout_latest arc_<?php echo $this->archive->id; ?> block<?php echo $this->class; ?>">

  <?php if ($this->hasMetaFields): ?>
    <p class="info"><time datetime="<?php echo $this->datetime; ?>"><?php echo $this->date; ?></time> <?php echo $this->author; ?> <?php echo $this->commentCount; ?></p>
  <?php endif; ?>

  <?php if (!$this->addBefore): ?>
    <h2><?php echo $this->linkHeadline; ?></h2>

    <div class="teaser">
      <?php echo $this->teaser; ?>
    </div>
  <?php endif; ?>

  <?php if ($this->addImage): ?>
    <figure class="image_container<?php echo $this->floatClass; ?>"<?php if ($this->margin || $this->float): ?> style="<?php echo trim($this->margin . $this->float); ?>"<?php endif; ?>>

      <?php if ($this->href): ?>
        <a href="<?php echo $this->href; ?>"<?php echo $this->attributes; ?> title="<?php echo $this->alt; ?>">
      <?php endif; ?>

      <img src="<?php echo $this->src; ?>"<?php echo $this->imgSize; ?> alt="<?php echo $this->alt; ?>">

      <?php if ($this->href): ?>
        </a>
      <?php endif; ?>

      <?php if ($this->caption): ?>
        <figcaption class="caption" style="width:<?php echo $this->arrSize[0]; ?>px"><?php echo $this->caption; ?></figcaption>
      <?php endif; ?>

    </figure>
  <?php endif; ?>

  <?php if ($this->addBefore): ?>
    <h2><?php echo $this->linkHeadline; ?></h2>

    <div class="teaser">
      <?php echo $this->teaser; ?>
    </div>
  <?php endif; ?>

  <?php if ($this->text || $this->teaser): ?>
    <p class="more"><?php echo $this->more; ?></p>
  <?php endif; ?>

</div>

Alternatively the meta fields could also be included into the addBefore condition.

Including the addBefore property into the template itself should not create a BC break - addImageToTemplate in Controller defaults addBefore to true whenever the floating value is not below - thus the above template would create the same output as the current default template when the user did not set the property to below.

@k-webdesign
Copy link

Isn't it possible to have this reworked template as a regular feature in Contao for news_full, news_latest, etc.? Editors choose any image alignment and wonder why it's not working 🤷🏼‍♀️

@fritzmg
Copy link
Contributor Author

fritzmg commented Nov 30, 2018

Contao 4's news_full template uses it now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants