Skip to content

Passing data through a partial to a grandchild partial results in "NULL" #2671

Closed

Description

@austriker27

Bug Description

I'm attempting to pass data from the CMS via a {{ collection }} loop through a child partial to the origin's grandchild partial. This is because I have a base card partial that I've extended with modified card partials like _card_featured

I think this is a bug based on my testing. I've tried a bunch of different solutions including different syntax, raw modifier and scoping the passed data.

Example:

Parent HTML:

    {{ partial:blog_posts/card_featured
        :p_background_color="background_color"
        :p_title="card:title"
    }}
    {{ /collection:blog_posts }}

blog_posts/card_featured partial:

{{ partial:components/card classes="bg-gradient-to-br from-{p_background_color} to-{p_background_color}-900
text-white" }}
<div class="p-4">
    <h3>{{ title }}</h3>
</div>
{{ /partial:components/card }}

_card.antlers.html (base card):

<a href="#" class="flex flex-col rounded-sm shadow group {{ classes }}">
    {{ slot }}
</a>

How to Reproduce

I have replicated the issue in a new clean Statamic V3 repo and stripped out all unnecessary things.

  1. Clone this repo: https://github.com/austriker27/statamic-partial-grandchild
  2. Inspect the centered <a> tag on the page and you will see the gradient classes have NULL in them. However when you {{ dump }} you will see the data is correct there.
    Rendered HTML:
<a href="#" class="flex flex-col rounded-sm shadow group bg-gradient-to-br from-NULL to-NULL-900
text-white">
    <div class="p-4">
    <h3>Yada, yada, yada...</h3>
</div>
</a>

Extra Detail

YAML file with the background_color data

Environment

Statamic 3.0.19 Solo
Laravel 8.10.0
PHP 7.4.8
No addons installed

Install method (choose one):

  • Fresh install from statamic/statamic

Thanks gents! Statamic is the best thing ever and I appreciate you.

Activity

  1. duncanmcclean commented on Oct 17, 2020

    @duncanmcclean
    Member

    Alright, after I bit of playing around, I think I figured out the issue.

    In the _card_featured partial, when you are calling the other partial, it's split into two lines, this bit below...

    {{ partial:components/card classes="bg-gradient-to-br from-{p_background_color} to-{p_background_color}-900
    text-white" }}
    

    If you were to put it into a single line like so, it starts working... as if by magic.

    {{ partial:components/card classes="bg-gradient-to-br from-{p_background_color} to-{p_background_color}-900 text-white" }}
    

    Hopefully that solves the problem for you. Thanks for creating the demo repo, super helpful!

    I'm keeping this issue open because fixing parameter values being split into multiple lines might be a bug that should be fixed.

  2. austriker27 commented on Oct 17, 2020

    @austriker27
    Author

    Whoa, now that is very interesting. I swear I tried to fix that line break (which was from my prettier/eslint/edtior config I think) and it still didnt work. Thanks for digging in @damcclean, I'll try that on my repo and let you know.

  3. austriker27 commented on Oct 17, 2020

    @austriker27
    Author

    Follow up: I can confirm fixing the line break fixed my particular issue! Thanks so much Duncan! I'm actually happy it was just an error in my code rather than error in the gentlemen's code. 😀

    Should I close this? Or if its left open, rename it?

  4. duncanmcclean commented on Oct 17, 2020

    @duncanmcclean
    Member

    Just keep it open until the gents confirm if it's something that should be fixed or not.

  5. jasonvarga commented on Oct 23, 2020

    @jasonvarga
    Member

    Yeah line breaks like that shouldn't affect it. This is a bug.

  6. deleted a comment from github-actions on Jul 6, 2021
  7. deleted a comment from austriker27 on Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions