New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope breaks and not fixable when using Partial and Relate tags inside a Collection tag with pagination #733

Closed
igregson opened this Issue Jun 5, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@igregson

igregson commented Jun 5, 2016

Steps to reproduce

  1. Create two collections
  2. Use the collection tag to pull content from each collection
  3. Include a partial or relate tag inside of the collection tag
  4. Scope is broken (and unable to be fixed via referencing the current item's scope)

Expected behaviour

Tags like partial and relate should not break the scope when used inside of a collections tag that's using pagination.

Actual behaviour

Using tag like partial and relate should not break the scope when used inside of a collections tag that's using pagination.

Server configuration

Operating system: Ubuntu 16.04

Web server: php cli

PHP version: 7.0.4

Statamic version: 2.0.7

Updated from an older Statamic or fresh install:

Updated from beta (via replacing statamic/

Logs

Web server error log

n/a

Statamic error log (/local/storage/logs/statamic.log)

[2016-06-05 19:48:26] dev.ERROR: Cannot render an array variable as a string: {{ item }}

Browser log

n/a

@igregson igregson changed the title from Certain Tags inside a Collection tag with pagination break scope to Scope breaks and not fixable when using Partial and Relate tags inside a Collection tag with pagination Jun 5, 2016

@igregson

This comment has been minimized.

igregson commented Jun 7, 2016

Example template code that recreates this:

{{ collection from="blog|news" sort="date:desc" as="items" paginate="true" limit="15" }} 

  {{ items }} 

    {{ if collection == "news" }}
      <h2>{{ title }}</h2>
      {{ if image }}
        <img src="{{ image | url }}" alt="">
      {{ /if }}
    {{ /if }}

    {{ if collection == "blog" }}
      <h2>{{ title }}</h2>
      {{ if primary_image }}
        <img src="{{ primary_image | url }}" alt="">
      {{ /if }}

      {{ if tags }}
        <span class="excerpt-meta mr1">Tagged in:</span>
        {{ tags }}

          <!-- PROBLEM HERE -->

          <!-- This breaks the scope and creates duplicate content (images where excerpts have no images) -->

          {{ relate:tags }}
            <a style="font-size:.85rem" href="{{ url }}">{{ title }}</a>
            {{ if count > 0 && !last }}, {{ /if }}
          {{ /relate:tags }}

          <!-- This also breaks the scope and also creates duplicate content (images where excerpts have no images) -->

          {{ taxonomy:tags id:is="{id}" }}
            <a style="font-size:.85rem" href="{{ url }}">{{ title }}</a>
            {{ if count > 0 && !last }}, {{ /if }}
          {{ /taxonomy:tags }}
        {{ /tags }}
      {{ /if }}

    {{ /if }}
  {{ /items }} 


  <!-- PAGINATION -->

  {{ paginate }}
    <div class="mt4 mb4 grid">
      {{ if next_page }}
        <div class="c-50">
          <a href="{{ next_page }}" class="fit btn btn-outline">⬅ Older Posts</a>
        </div>
      {{ /if }}
      {{ if prev_page }}
        <div class="c-50">
          <a href="{{ prev_page }}" class="fit btn btn-outline">Newer Posts ➡</a>
        </div>
      {{ /if }}
      <div class="clearfix"></div>
    </div> 
  {{ /paginate }} 

{{ /collection }}

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Jun 7, 2016

{{ collection ... }} 
  {{ items scope="item" }}
    {{ item:url }} {{ item:title }} etc
  {{ /items }}
{{ /collection }}

Add scope to your items array, then the values of that specific iteration will be accessible through that scope alone.

@igregson

This comment has been minimized.

igregson commented Jun 7, 2016

That did the trick... should have thought to try that.

Thank you!

@igregson igregson closed this Jun 7, 2016

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented Sep 6, 2016

This was a bug and has been fixed for 2.1.7.

The scope solution was just a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment