Only wrap when content is actually trimmed

Created on 26 June 2020, almost 4 years ago
Updated 20 February 2024, 4 months ago

Right now when the wrapper option is enabled it always adds the wrapper, even if the content was short enough to not be trimmed or we are displaying an untrimmed summary. It would be nice to style off the wrapper only when trimming has actually taken place.

Feature request
Status

Fixed

Version

2.1

Component

Code

Created by

🇺🇸United States rwohleb

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇪Ireland lostcarpark

    Just looking back at this issue. If we move to a .twig template, it may be difficult to only apply the template if the field was trimmed. Could we achieve the same thing by adding a class that indicates whether the content was trimmed or not?

  • 🇮🇪Ireland lostcarpark

    Actually, if we just add a boolean flag to the variables passed into the template file, indicating whether the field was trimmed or not, the theme could use it however it likes. It would then be a simple matter to use an {% if %} to apply the wrapper, or modify the output as required.

  • 🇺🇸United States ultimike Florida, USA

    @lostcarpark's idea in comment 9 sounds good to me. Simple, elegant, flexible.

    Obviously, we should add the variable name to a comment at the top of the Twig file that Add config option for more link wrapper Fixed will add 😀

    -mike

  • Status changed to Postponed about 1 year ago
  • 🇮🇪Ireland lostcarpark

    Marking postponed pending merge of Add config option for more link wrapper Fixed .

    It should be a fairly simple change, but discussed with @ultimike and agreed that change is already quite complex, so wrapping this change in with it would likely cause confusion. I'm happy to work on it when that change has been merged.

  • Assigned to lostcarpark
  • Status changed to Needs work about 1 year ago
  • 🇮🇪Ireland lostcarpark

    Opened MR !54, which adds new variable, is_trimmed to Twig file.
    Added test to verify.
    Test adds {% if is_trimmed %} to test template, and checks for it in test case.

  • Status changed to Needs review about 1 year ago
  • Pipeline finished with Success
    6 months ago
    Total: 451s
    #68219
  • Pipeline finished with Success
    6 months ago
    Total: 331s
    #68222
  • 🇮🇪Ireland lostcarpark

    Rebased !54 (manual rebase required because two branches had added a function to SmartTrimTemplateTest, which git found difficult to merge automatically).

    All tests passing, except known "new static()" issue in phpstan.

    I think this change makes sense because it allows the .twig template to decide whether to wrap the output using the is_trimmed flag, without adding an additional option to the configuration.

  • Status changed to Needs work 5 months ago
  • 🇺🇸United States ultimike Florida, USA

    Forgive me if I'm missing something (it's been awhile since I looked at this issue), but this MR doesn't actually use the new is_trimmed twig variable, correct? Shouldn't we be updating line 19 of smart-trim.html.twig file to something like:

    {% if wrap_output == true and is_trimmed == true %}

    It's entirely possible that I'm misreading things - feel free to correct me if I'm wrong.

    -mike

  • Pipeline finished with Success
    5 months ago
    Total: 272s
    #87513
  • 🇮🇪Ireland lostcarpark

    You're correct that it's not currently using is_trimmed in the default template. I'm not sure that it needs to be.

    The aim of the change was to make the is_trimmed variable available to the .twig template for those that want to use it.

    If people feel that there's value in using it in the default template, I'm happy to add it.

  • Pipeline finished with Success
    5 months ago
    Total: 372s
    #87520
  • 🇮🇪Ireland lostcarpark

    Rebased on the latest 2.1.x.

    Next major is currently failing, but I don't think it's caused by anything in this MR.

  • Status changed to Needs review 5 months ago
  • Pipeline finished with Skipped
    5 months ago
    #88936
  • Status changed to Fixed 5 months ago
  • 🇺🇸United States ultimike Florida, USA

    @markie let me know via Slack DM that he's good with this change as well - merged!

    thanks,
    -mike

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024