statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Reused Partials #2368

Open KimKJDesigns opened 5 years ago

KimKJDesigns commented 5 years ago

When cascading, reused partials are difficult to scope. Given the following example, I'd like to use the same partial for 3 areas in my template.

Pages Template

{{ page_builder }}
    {{ text_layouts scope="content_section" }}
        {{ if type == "text_layout_1" }}
            {{ partial:blocks/text/text_layout_1 }}
        {{ /if }}
    {{ /text_layouts }}
{{ /page_builder }}

Text Layout Partial

<section id="{{ section_id | slugify }}" class="{{ partial:settings/section_class }}" >
    {{ partial:elements/background_video }}
    <div class="{{ section_container }}">
        {{ content_row scope="content_row" }}
        <div id="{{ content_row_id | slugify }}" class="row {{ partial:settings/content_row_class }}">
            {{ content_column scope="content_column" }}
                <div id="{{ content_id | slugify }}" class="{{ partial:settings/content_column_class }}">
                    {{ partial:elements/bard :bard_content="content_column:content" }}
                </div>
            {{ /content_column }}
        </div>
        {{ /content_row }}
    </div>
</section>

Section Class Partial

{{ section_hidden_devices join=" " }} {{ section_spacing }} {{ section_height }} {{ background_colour }} {{ partial:settings/background_image }} {{ partial:settings/background_video }} {{ justification }} {{ section_class }}

Content Row Class Partial

{{ partial:settings/animation }} {{ partial:settings/box }} {{ partial:settings/background_image }} {{ partial:settings/background_video }} {{ justification }} {{ content_row_class }}

Background Video Partial

{{ if background_video_type }}videobg{{ /if }}

Given the following, if background_video_type is active for scope of content_section, it still cascades through to the next scope content_row_css. This means background_video_type is still true/valid for the content_row, even if it isn't.

Therefore I should scope it, however, I cannot scope partial variables if you plan on using them in more than one scope.

Describe the solution you'd like I have found a solution to this, see below, however I'd like to see (in v3) the following option. {{ partial:settings/section_class is_scoped='true' }} or {{ partial:settings/section_class is_scoped='content_section' }}.

is_scoped='true' would automatically scope the partials variables to the last/parent scope. is_scoped='content_section' would define a scope the partials variables should use.

Describe alternatives you've considered I have a solution for the current build, however it isn't elegant and involves creating more arrays/variables to serve the data.

{{ partial:settings/section_class :data='content_section' }}.

Section Class Partial

{{ data:section_hidden_devices join=" " }} {{ data:section_spacing }} {{ data:section_height }} {{ data:background_colour }} {{ partial:settings/background_image :data='data' }} {{ partial:settings/background_video :data='data' }} {{ data:justification }} {{ data:section_class }}

Background Video Partial

{{ if data:background_video_type }}videobg{{ /if }}

Unfortunately, for this solution, it's all in. There is no sprinkle of it here and there, I need to commit to every partial variable requiring a scope.